Learn Laravel MCQs

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

How do you redirect to a named route in Laravel?

1) return redirect()->route()

2) return redirect()->url()

3) return redirect()->toRoute()

4) return route()

Answer : Option 1

What does the `sync()` method do in Laravel relationships?

1) Syncs intermediate table records for a many-to-many relationship

2) Syncs the database schema with migrations

3) Synchronizes session data

4) Syncs a controller with a view

Answer : Option 1

Which helper function is used to log messages in Laravel?

1) log()

2) debug()

3) info()

4) logger()

Answer : Option 4

How do you define custom Blade directives in Laravel?

1) Blade::directive()

2) Blade::custom()

3) Blade::addDirective()

4) Blade::create()

Answer : Option 1

What does Laravel’s `with()` method do when returning a view?

1) Passes data to the view

2) Binds a model to a route

3) Includes a sub-view

4) Redirects with session data

Answer : Option 1

How do you make a model event observer in Laravel?

1) php artisan make:observer

2) php artisan create:observer

3) php artisan generate:observer

4) php artisan event:observer

Answer : Option 1

Which Laravel service provides support for broadcasting events?

1) Broadcast

2) Event

3) Queue

4) Socket

Answer : Option 1

How do you enable maintenance mode in Laravel?

1) php artisan down

2) php artisan up

3) php artisan enable:maintenance

4) php artisan set:down

Answer : Option 1

What is the purpose of the `Middleware` in Laravel?

1) Filter HTTP requests

2) Handle database queries

3) Manage session data

4) Handle file uploads

Answer : Option 1

How do you retrieve the authenticated user in Laravel?

1) Auth::user()

2) User::auth()

3) Session::user()

4) Auth::check()

Answer : Option 1