This flow shows how you open the terminal, run the Artisan command to create a controller, and then use the new controller in your Laravel app.
Execution Sample
Laravel
php artisan make:controller PhotoController
// Creates a new controller named PhotoController
// File saved in app/Http/Controllers/PhotoController.php
This command creates a new controller file named PhotoController in the Laravel project.
💡 Controller file created and ready to use in routes or app logic
Variable Tracker
Variable
Start
After Step 2
After Step 3
Final
Controller File
Does not exist
Created at app/Http/Controllers/PhotoController.php
Exists with class skeleton
Ready to use in app
Key Moments - 3 Insights
Why doesn't the controller file appear immediately after running the command?
The file is created during Step 2, but you must check the file system or IDE in Step 3 to see it. The execution_table shows the file creation happens after the command runs.
Can I name the controller anything I want?
Yes, but by convention, controller names end with 'Controller'. The command in Step 2 uses 'PhotoController' as an example following this rule.
What happens if I run the command twice with the same name?
Laravel will not overwrite the existing controller file without warning; instead, it will display an error indicating the file already exists. The execution_table does not show this, but it's important to avoid accidental overwrites.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result immediately after running the Artisan command in Step 2?
ATerminal closes
BRoute is automatically added to routes/web.php
CController file is created at app/Http/Controllers/PhotoController.php
DNothing happens
💡 Hint
Check the 'Result' column in Step 2 of the execution_table
At which step does the controller file become ready to use in the app?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the 'Result' column for Step 3 in the execution_table
If you change the controller name in the command, how does the variable 'Controller File' change in variable_tracker?
AThe file path stays the same
BThe file path changes to match the new controller name
CThe file is created in a different folder
DNo file is created
💡 Hint
Variable tracker shows the file path includes the controller name after creation
Concept Snapshot
Use Artisan to create controllers quickly:
php artisan make:controller ControllerName
Creates a new controller file in app/Http/Controllers
Name controllers with 'Controller' suffix by convention
Use the new controller in routes or app logic
Avoid overwriting existing controllers accidentally
Full Transcript
This visual execution shows how to create a controller in Laravel using Artisan. First, open your terminal in the project folder. Then run the command 'php artisan make:controller PhotoController'. This creates a new file named PhotoController.php inside app/Http/Controllers. You can check the file to see the basic controller class. Finally, you can use this controller in your routes by pointing a route to one of its methods. The controller is now ready to handle web requests. Remember to follow naming conventions and be careful not to overwrite files.
Practice
(1/5)
1. What does the Artisan command php artisan make:controller do in a Laravel project?
easy
A. It runs the Laravel server to test the application.
B. It creates a new controller file in the app/Http/Controllers directory.
C. It installs Laravel dependencies via Composer.
D. It creates a new database migration file.
Solution
Step 1: Understand the purpose of the make:controller command
The command php artisan make:controller is designed to generate a new controller file automatically.
Step 2: Identify the location of the created controller
By default, the new controller is placed in the app/Http/Controllers directory to organize application logic.
Final Answer:
It creates a new controller file in the app/Http/Controllers directory. -> Option B
Confusing make:controller with server start commands
Thinking it creates migrations or installs packages
Assuming it runs the app instead of creating files
2. Which of the following is the correct Artisan command to create a resource controller named ProductController?
easy
A. php artisan make:controller ProductController --resource
B. php artisan create:controller ProductController --resource
C. php artisan make:controller ProductController -r
D. php artisan generate:controller ProductController --resource
Solution
Step 1: Recall the correct Artisan syntax for resource controllers
The correct command uses make:controller with the --resource option to generate all resource methods.
Step 2: Verify the command spelling and options
Only php artisan make:controller ProductController --resource matches Laravel's official syntax exactly.
Final Answer:
php artisan make:controller ProductController --resource -> Option A
Quick Check:
Use make:controller with --resource option [OK]
Hint: Use make:controller with --resource for full methods [OK]
Common Mistakes:
Using create:controller or generate:controller commands
Using short option -r which is invalid
Misspelling make:controller
3. What will be the result of running php artisan make:controller UserController --resource in a Laravel project?
medium
A. Creates a UserController with methods like index, create, store, show, edit, update, and destroy.
B. Creates a UserController with only an index method.
C. Creates a UserController without any methods inside.
D. Throws an error because --resource is not a valid option.
Solution
Step 1: Understand the --resource option effect
The --resource flag tells Artisan to generate a controller with all standard resource methods.
Step 2: List the methods generated
These methods include index, create, store, show, edit, update, and destroy.
Final Answer:
Creates a UserController with methods like index, create, store, show, edit, update, and destroy. -> Option A
Quick Check:
--resource adds all resource methods [OK]
Hint: --resource adds all common controller methods [OK]
Common Mistakes:
Thinking it creates empty controller without methods
Assuming only index method is created
Believing --resource is invalid option
4. You run php artisan make:controller AdminController -resource but get an error. What is the likely cause?
medium
A. AdminController name is reserved and cannot be used.
B. The make:controller command requires a namespace option.
C. You must run the command inside the database directory.
D. The short option -resource is invalid; it should be --resource.
Solution
Step 1: Check the option syntax used
The command uses -resource which is incorrect; Laravel requires double dashes for options.
Step 2: Confirm correct option format
The correct option is --resource with two dashes, not one.
Final Answer:
The short option -resource is invalid; it should be --resource. -> Option D
Quick Check:
Options need double dashes like --resource [OK]
Hint: Use double dashes for options like --resource [OK]
Common Mistakes:
Using single dash for long options
Thinking controller names are restricted
Running commands outside project root
5. You want to create a controller named OrderController that includes resource methods and also API-specific methods without views. Which Artisan command should you use?
hard
A. php artisan make:controller OrderController --resource
B. php artisan make:controller OrderController --api
C. php artisan make:controller OrderController --resource --api
D. php artisan make:controller OrderController --viewless
Solution
Step 1: Understand the need for resource and API methods
You want all resource methods but tailored for API use, which excludes view-related methods.
Step 2: Identify the correct Artisan options
The --resource option adds resource methods, and --api modifies them to exclude create/edit views.
Step 3: Combine options correctly
Using both --resource --api together creates a resource controller optimized for API.
Final Answer:
php artisan make:controller OrderController --resource --api -> Option C
Quick Check:
Use --resource and --api for API resource controllers [OK]
Hint: Combine --resource and --api for API-only controllers [OK]
Common Mistakes:
Using only --api which creates minimal controller
Using --resource alone which includes view methods
Assuming --viewless is a valid option
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.