Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
What is the default session driver in Laravel?
1) file
2) database
3) array
4) cookie
Answer : file
How do you send an email in Laravel?
1) Mail::send()
2) Email::dispatch()
3) Mail::create()
4) Mail::compose()
Answer : Mail::send()
What is the command to create a new resource controller in Laravel?
1) php artisan make:controller ControllerName --resource
2) artisan create:controller ControllerName --resource
3) make:resource ControllerName
4) create:resource ControllerName
Answer : php artisan make:controller ControllerName --resource
How do you retrieve the current authenticated user in Laravel?
1) auth()->user()
2) Auth::current()
3) user()->auth()
4) Auth::user()
Answer : auth()->user()
What is the purpose of the `config` directory in Laravel?
1) Store configuration files
2) Store route files
3) Store migration files
4) Store view files
Answer : Store configuration files
How do you add a custom route to a resource controller in Laravel?
1) Route::resource("name", "ControllerName")->except("method")
2) Route::resource("name", "ControllerName")->add("method")
3) Route::resource("name", "ControllerName")->with("method")
4) Route::resource("name", "ControllerName")->custom("method")
Answer : Route::resource("name", "ControllerName")->except("method")
How do you retrieve a session variable in Laravel?
1) session("key")
2) session()->get("key")
3) Session::get("key")
4) getSession("key")
Answer : session("key")
What is the purpose of the `public` directory in Laravel?
1) Store publicly accessible assets
2) Store configuration files
3) Store application logs
4) Store database migrations
Answer : Store publicly accessible assets
How do you perform a redirect in Laravel?
1) return redirect("/path")
2) redirect("/path")
3) return to("/path")
4) redirectTo("/path")
Answer : return redirect("/path")
What is the purpose of the `php artisan migrate` command?
1) Run database migrations
2) Rollback migrations
3) Create new migrations
4) Show migration status
Answer : Run database migrations