Learn Laravel MCQs

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

What is the command to create a new database migration in Laravel?

1) php artisan make:migration

2) artisan create:migration

3) make:migration

4) create:migration

Answer : Option 1

How do you check if a user is an admin in Laravel?

1) auth()->user()->isAdmin()

2) isAdmin()

3) Auth::user()->isAdmin()

4) user()->isAdmin()

Answer : Option 1

What is the command to install Laravel in a new directory?

1) composer create-project --prefer-dist laravel/laravel

2) composer install laravel

3) laravel new

4) artisan create

Answer : Option 1

How can you access the database connection in Laravel?

1) DB::connection()

2) DB::getConnection()

3) DB::connect()

4) DB::get()

Answer : Option 1

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

1) Route::resource()

2) Route::createResource()

3) Route::newResource()

4) Route::resourceRoute()

Answer : Option 1

How do you define a route with a parameter in Laravel?

1) Route::get("/user/{id}")

2) Route::get("/user/")

3) Route::get("/user[id]")

4) Route::get("/user/:id")

Answer : Option 1

What is the command to generate a new controller with resource methods in Laravel?

1) php artisan make:controller --resource

2) artisan create:controller --resource

3) make:controller --resource

4) create:controller --resource

Answer : Option 1

How do you run unit tests in Laravel?

1) php artisan test

2) php artisan run:test

3) artisan test

4) run:test

Answer : Option 1

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

1) php artisan make:policy

2) artisan create:policy

3) make:policy

4) create:policy

Answer : Option 1

How do you create a new database seed in Laravel?

1) php artisan make:seeder

2) artisan create:seeder

3) make:seeder

4) create:seeder

Answer : Option 1