Learn Laravel MCQs

Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.

How do you handle exceptions in Laravel?

1) handle()

2) exception()

3) Exception::handle()

4) app/Exceptions/Handler.php

Answer : app/Exceptions/Handler.php

What is the command to generate a new middleware class in Laravel?

1) php artisan make:middleware

2) artisan create:middleware

3) make:middleware

4) create:middleware

Answer : php artisan make:middleware

What is the default logging driver in Laravel?

1) stack

2) single

3) daily

4) syslog

Answer : stack

How do you generate a new API resource controller in Laravel?

1) php artisan make:controller --api

2) php artisan make:controller --resource

3) make:controller --api

4) artisan create:controller --api

Answer : php artisan make:controller --api

What is the command to create a new route in Laravel?

1) Route::get()

2) Route::create()

3) php artisan make:route

4) create:route

Answer : Route::get()

How can you create a new middleware in Laravel?

1) php artisan make:middleware

2) artisan create:middleware

3) make:middleware

4) create:middleware

Answer : php artisan make:middleware

What is the command to generate a new notification in Laravel?

1) php artisan make:notification

2) artisan create:notification

3) make:notification

4) create:notification

Answer : php artisan make:notification

How do you define a one-to-many polymorphic relationship in Eloquent?

1) morphMany()

2) hasMany()

3) belongsTo()

4) morphTo()

Answer : morphMany()

What is the command to create a new event listener in Laravel?

1) php artisan make:listener

2) artisan create:listener

3) make:listener

4) create:listener

Answer : php artisan make:listener

How do you create a new service provider in Laravel?

1) php artisan make:provider

2) artisan create:provider

3) make:provider

4) create:provider

Answer : php artisan make:provider