Laravel Controller Artisan Commands Cheat Sheet

Laravel Commands

1. Basic Controller Creation:

php artisan make:controller MyController

2. Controller with Resource Methods (CRUD):

php artisan make:controller MyController --resource

CRUD (Create, Read, Update, Delete) operations:

  • index: Display a listing of the resource.
  • create: Show the form for creating a new resource.
  • store: Store a newly created resource in storage.  
  • show: Display the specified resource.
  • edit: Show the form for editing the specified resource.
  • update: Update the specified resource in storage.
  • destroy: Remove the specified resource from storage.  

3. Controller with API Resource Methods:

php artisan make:controller MyController --api

Similar to --resource, but it generates a controller optimized for API endpoints.

4. Invokable Controller (Single Action):

php artisan make:controller MyController --invokable

This creates a controller with a single __invoke method.