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

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

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

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

How can you define a custom Blade directive?

1) Blade::directive()

2) Blade::addDirective()

3) Blade::define()

4) Blade::custom()

Answer : Option 1

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

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

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

How do you define a many-to-many relationship in Eloquent?

1) belongsToMany()

2) hasMany()

3) hasOne()

4) oneToMany()

Answer : Option 1

What is the purpose of the `app/Providers` directory?

1) Store service providers

2) Store controllers

3) Store middleware

4) Store routes

Answer : Option 1