Learn Laravel MCQs

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

How can you define a default value for a column in a migration?

1) ->default(value)

2) ->setDefault(value)

3) ->withDefault(value)

4) ->addDefault(value)

Answer : Option 1

What is the command to create a new middleware class in Laravel?

1) php artisan make:middleware MiddlewareName

2) artisan create:middleware MiddlewareName

3) make:middleware MiddlewareName

4) create:middleware MiddlewareName

Answer : Option 1

How do you specify a route parameter constraint in Laravel?

1) Route::get("/user/{id}", "UserController@show")->where("id", "[0-9]+")

2) Route::get("/user/{id}")->whereNumber("id")

3) Route::get("/user/{id}")->whereAlpha("id")

4) Route::get("/user/{id}")->with("id", "[0-9]+")

Answer : Option 1

What is the command to create a new form request class in Laravel?

1) php artisan make:request RequestName

2) artisan create:request RequestName

3) make:request RequestName

4) create:request RequestName

Answer : Option 1

How do you send an email in Laravel?

1) Mail::send()

2) Mail::to()->send()

3) Mail::dispatch()

4) sendMail()

Answer : Option 1

What is the command to generate a new seeder with a specific name?

1) php artisan make:seeder SeederName

2) artisan create:seeder SeederName

3) make:seeder SeederName

4) create:seeder SeederName

Answer : Option 1

How do you create a one-to-one relationship in Eloquent?

1) hasOne()

2) belongsTo()

3) hasMany()

4) oneToOne()

Answer : Option 1

What is the purpose of the `.env` file in Laravel?

1) Store environment variables

2) Store routes

3) Store configuration

4) Store sessions

Answer : Option 1

How do you define a controller action for a resource route?

1) ControllerName@index

2) ControllerName@show

3) ControllerName@resource

4) ControllerName@method

Answer : Option 1

What is the command to run all migrations in Laravel?

1) php artisan migrate

2) php artisan db:migrate

3) php artisan run:migrations

4) php artisan migrate:all

Answer : Option 1