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

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

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

1) request()

2) app()->request

3) Request::instance()

4) getRequest()

Answer : Option 1

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

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

How do you perform a database transaction in Laravel?

1) DB::transaction()

2) DB::beginTransaction()

3) DB::commit()

4) DB::rollBack()

Answer : Option 1

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

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

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

How can you access the database connection in Laravel?

1) DB::connection()

2) database()->connection()

3) DB::getConnection()

4) app()->database()

Answer : Option 1