Learn Laravel MCQs

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

How do you create a new resource route in Laravel?

1) Route::resource("name", "ControllerName")

2) Route::getResource("name", "ControllerName")

3) Route::addResource("name", "ControllerName")

4) Route::createResource("name", "ControllerName")

Answer : Route::resource("name", "ControllerName")

What is the purpose of the `config/database.php` file?

1) Store database connections

2) Store application configuration

3) Store routes

4) Store middleware

Answer : Store database connections

How do you access the application's request instance in Laravel?

1) request()

2) app()->request

3) Request::instance()

4) getRequest()

Answer : request()

What is the command to generate a new database factory in Laravel?

1) php artisan make:factory FactoryName

2) artisan create:factory FactoryName

3) make:factory FactoryName

4) create:factory FactoryName

Answer : php artisan make:factory FactoryName

How do you handle multiple session drivers in Laravel?

1) Set in .env file

2) Set in config/session.php

3) Set in config/database.php

4) Set in config/app.php

Answer : Set in .env file

How do you perform a database transaction in Laravel?

1) DB::transaction()

2) DB::beginTransaction()

3) DB::commit()

4) DB::rollBack()

Answer : DB::transaction()

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

1) php artisan make:bus

2) artisan create:bus

3) make:bus

4) create:bus

Answer : php artisan make:bus

How do you define a default fallback route in Laravel?

1) Route::fallback()

2) Route::default()

3) Route::any("*", "Controller@method")

4) Route::catchAll()

Answer : Route::fallback()

What is the command to clear the route cache in Laravel?

1) php artisan route:clear

2) php artisan clear:routes

3) php artisan clear:cache

4) php artisan cache:clear

Answer : php artisan route:clear

How can you access the database connection in Laravel?

1) DB::connection()

2) database()->connection()

3) DB::getConnection()

4) app()->database()

Answer : DB::connection()