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 : Store publicly accessible files
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 : php artisan make:job JobName
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 : php artisan make:seeder SeederName
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 : Route::get("/user/{id}", "UserController@show")
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 : Store environment variables
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 : php artisan make:controller ControllerName
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 : php artisan make:middleware MiddlewareName
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 : Route::get("/path", "Controller@method")
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 : Store application logs
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 : By implementing the Rule interface