Learn Laravel MCQs

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

What is the purpose of the `public` directory in Laravel?

1) Store publicly accessible files

2) Store logs

3) Store sessions

4) Store application files

Answer : Option 1

How do you create a new job class in Laravel?

1) php artisan make:job JobName

2) artisan create:job JobName

3) make:job JobName

4) create:job JobName

Answer : Option 1

What is the command to create a new seeder in Laravel?

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 new route with parameters in Laravel?

1) Route::get("/user/{id}", "UserController@show")

2) Route::get("/user/:id", "UserController@show")

3) Route::get("/user?id=id", "UserController@show")

4) Route::get("/user?id={id}", "UserController@show")

Answer : Option 1

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

1) Store environment variables

2) Store database configurations

3) Store route definitions

4) Store session data

Answer : Option 1

How do you generate a new controller in Laravel?

1) php artisan make:controller ControllerName

2) artisan create:controller ControllerName

3) make:controller ControllerName

4) create:controller ControllerName

Answer : Option 1

What is the command to create a new middleware 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 define a new route in Laravel?

1) Route::get("/path", "Controller@method")

2) Route::define("/path", "Controller@method")

3) Route::add("/path", "Controller@method")

4) Route::route("/path", "Controller@method")

Answer : Option 1

What is the purpose of the `storage` directory in Laravel?

1) Store application logs

2) Store database migrations

3) Store application caches

4) Store public assets

Answer : Option 1

How can you create a custom validation rule in Laravel?

1) By extending the Validator class

2) By implementing the Rule interface

3) By creating a new validation class

4) By using the validate method

Answer : Option 1