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 : Option 1

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 : Option 1

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 : Option 1

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 : Option 1

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 : Option 1

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 : Option 1

How can you access configuration values in Laravel?

1) config("app.name")

2) config("app.settings")

3) getConfig("app.name")

4) app("config")

Answer : Option 1

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 : Option 1

How do you handle exceptions in Laravel?

1) AppExceptionsHandler

2) ExceptionHandler

3) app()->exception()

4) handleException()

Answer : Option 1

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 : Option 1