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 : php artisan make:migration
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 : auth()->user()->isAdmin()
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 : composer create-project --prefer-dist laravel/laravel
How can you access the database connection in Laravel?
1) DB::connection()
2) DB::getConnection()
3) DB::connect()
4) DB::get()
Answer : DB::connection()
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 : Route::resource()
How do you define a route with a parameter in Laravel?
1) Route::get("/user/{id}")
2) Route::get("/user/<id>")
3) Route::get("/user[id]")
4) Route::get("/user/:id")
Answer : Route::get("/user/{id}")
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 : php artisan make:controller --resource
How do you run unit tests in Laravel?
1) php artisan test
2) php artisan run:test
3) artisan test
4) run:test
Answer : php artisan test
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 : php artisan make:policy
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 : php artisan make:seeder