Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
How do you retrieve the currently authenticated user in Laravel?
1) auth()->user()
2) Auth::user()
3) currentUser()
4) user()
Answer : auth()->user()
What is the command to create a new API resource controller in Laravel?
1) php artisan make:controller Api/ResourceNameController --resource
2) artisan create:controller Api/ResourceNameController --resource
3) make:controller Api/ResourceNameController --resource
4) create:controller Api/ResourceNameController --resource
Answer : php artisan make:controller Api/ResourceNameController --resource
How can you generate a new model class in Laravel?
1) php artisan make:model ModelName
2) artisan create:model ModelName
3) make:model ModelName
4) create:model ModelName
Answer : php artisan make:model ModelName
What is the purpose of the `routes/channels.php` file?
1) Define broadcast channels
2) Define API routes
3) Define web routes
4) Define console routes
Answer : Define broadcast channels
How do you define a route that responds to a specific HTTP method in Laravel?
1) Route::post("/url", "Controller@method")
2) Route::method("post", "/url", "Controller@method")
3) Route::addPost("/url", "Controller@method")
4) Route::request("POST", "/url", "Controller@method")
Answer : Route::post("/url", "Controller@method")
What is the command to create a new pivot table migration in Laravel?
1) php artisan make:migration create_table_name
2) artisan create:migration create_table_name
3) make:migration create_table_name
4) create:migration create_table_name
Answer : php artisan make:migration create_table_name
How can you access configuration values in Laravel?
1) config("app.name")
2) config("app.settings")
3) getConfig("app.name")
4) app("config")
Answer : config("app.name")
What is the command to list all available routes in Laravel?
1) php artisan route:list
2) php artisan routes
3) php artisan show:routes
4) php artisan list:routes
Answer : php artisan route:list
How do you handle exceptions in Laravel?
1) AppExceptionsHandler
2) ExceptionHandler
3) app()->exception()
4) handleException()
Answer : AppExceptionsHandler
What is the command to clear the compiled views in Laravel?
1) php artisan view:clear
2) php artisan clear:views
3) php artisan clear:compiled
4) php artisan clear
Answer : php artisan view:clear