Learn Laravel MCQs

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

What is the command to create a new view composer in Laravel?

1) php artisan make:composer ComposerName

2) artisan create:composer ComposerName

3) make:composer ComposerName

4) create:composer ComposerName

Answer : php artisan make:composer ComposerName

How do you create a new model factory in Laravel?

1) php artisan make:factory FactoryName

2) artisan create:factory FactoryName

3) make:factory FactoryName

4) create:factory FactoryName

Answer : php artisan make:factory FactoryName

What is the command to run a specific migration in Laravel?

1) php artisan migrate --path=/database/migrations/name.php

2) php artisan migrate:name

3) php artisan migrate:run --path=/database/migrations/name.php

4) php artisan migrate --file=name

Answer : php artisan migrate --path=/database/migrations/name.php

How do you define a route with a middleware group in Laravel?

1) Route::middleware(["middleware1", "middleware2"])->group()

2) Route::group(["middleware" => ["middleware1", "middleware2"]])

3) Route::addGroup(["middleware" => ["middleware1", "middleware2"]])

4) Route::groupWithMiddleware(["middleware1", "middleware2"])

Answer : Route::middleware(["middleware1", "middleware2"])->group()

What is the command to create a new custom helper in Laravel?

1) php artisan make:helper HelperName

2) artisan create:helper HelperName

3) make:helper HelperName

4) create:helper HelperName

Answer : php artisan make:helper HelperName

How can you handle route model binding in Laravel?

1) Route::bind()

2) Route::model()

3) Route::useModelBinding()

4) Route::autoBind()

Answer : Route::model()

What is the command to 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

How do you create a new Artisan command with a signature?

1) php artisan make:command CommandName --command="command:name"

2) artisan create:command CommandName --command="command:name"

3) make:command CommandName --command="command:name"

4) create:command CommandName --command="command:name"

Answer : php artisan make:command CommandName --command="command:name"

What is the command to dump the current database connection in Laravel?

1) php artisan db:connection

2) php artisan db:show

3) php artisan db:info

4) php artisan db:status

Answer : php artisan db:connection

How do you create 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