Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
How can you check the current environment in Laravel?
1) app()->environment()
2) env()
3) environment()
4) getEnvironment()
Answer : app()->environment()
What is the purpose of the `routes/api.php` file?
1) Define API routes
2) Define web routes
3) Define console routes
4) Define middleware routes
Answer : Define API routes
How do you create a new policy in Laravel?
1) php artisan make:policy PolicyName
2) artisan create:policy PolicyName
3) make:policy PolicyName
4) create:policy PolicyName
Answer : php artisan make:policy PolicyName
What is the command to rollback the last database migration in Laravel?
1) php artisan migrate:rollback
2) php artisan rollback:migrations
3) php artisan db:rollback
4) php artisan migrate:revert
Answer : php artisan migrate:rollback
How can you define a custom Blade directive?
1) Blade::directive()
2) Blade::addDirective()
3) Blade::define()
4) Blade::custom()
Answer : Blade::directive()
What is the command to refresh the database and run all migrations in Laravel?
1) php artisan migrate:refresh
2) php artisan migrate:reset
3) php artisan migrate:run
4) php artisan migrate:revert
Answer : php artisan migrate:refresh
How do you create a new service provider in Laravel?
1) php artisan make:provider ProviderName
2) artisan create:provider ProviderName
3) make:provider ProviderName
4) create:provider ProviderName
Answer : php artisan make:provider ProviderName
What is the command to generate a new validation rule in Laravel?
1) php artisan make:rule RuleName
2) artisan create:rule RuleName
3) make:rule RuleName
4) create:rule RuleName
Answer : php artisan make:rule RuleName
How do you define a many-to-many relationship in Eloquent?
1) belongsToMany()
2) hasMany()
3) hasOne()
4) oneToMany()
Answer : belongsToMany()
What is the purpose of the `app/Providers` directory?
1) Store service providers
2) Store controllers
3) Store middleware
4) Store routes
Answer : Store service providers