Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
Which command is used to roll back the last migration?
1) php artisan migrate:rollback
2) php artisan db:rollback
3) php rollback
4) php artisan migrate:reverse
Answer : Option 1
Which Laravel package is used for pagination?
1) Paginator
2) Paginate
3) PaginationHelper
4) LengthAwarePaginator
Answer : Option 4
How do you check if a record exists in Laravel?
1) DB::table()->exists()
2) Model::exists()
3) DB::table()->has()
4) DB::table()->find()
Answer : Option 1
Which of the following is a Laravel Blade directive?
1) @if
2) @check
3) @run
4) @repeat
Answer : Option 1
What is the default file extension for Laravel Blade templates?
1) .blade.html
2) .html.blade
3) .blade.php
4) .php.blade
Answer : Option 3
What is Laravel Homestead?
1) A database system
2) A virtual development environment
3) A PHP version
4) A templating engine
Answer : Option 2
Which command is used to generate a new model in Laravel?
1) php artisan make:model
2) php artisan create:model
3) php make model
4) php artisan build:model
Answer : Option 1
How do you define a one-to-many relationship in Laravel?
1) hasMany()
2) belongsTo()
3) hasOne()
4) hasManyThrough()
Answer : Option 1
Which of the following is used for API routing in Laravel?
1) web.php
2) routes.php
3) api.php
4) app.php
Answer : Option 3
How do you retrieve the last inserted ID in Laravel?
1) DB::getLastId()
2) DB::lastInsertId()
3) DB::table()->lastId()
4) DB::getPdo()->lastInsertId()
Answer : Option 4