Learn Laravel MCQs

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

How can you dispatch an event in Laravel?

1) event()

2) dispatch()

3) Event::fire()

4) fireEvent()

Answer : event()

What is the purpose of the `app/Http/Controllers` directory?

1) Store routes

2) Store controllers

3) Store middleware

4) Store requests

Answer : Store controllers

How do you define a route parameter in Laravel?

1) {parameter}

2) [parameter]

3) (parameter)

4) <parameter>

Answer : {parameter}

What command is used to view the application environment in Laravel?

1) php artisan env

2) php artisan config:show

3) php artisan env:show

4) php artisan environment

Answer : php artisan env

How do you create a new resource route in Laravel?

1) Route::resource()

2) Route::route()

3) Route::resourceRoute()

4) Route::newResource()

Answer : Route::resource()

What is the purpose of the `app/Providers` directory?

1) Store service providers

2) Store routes

3) Store controllers

4) Store middleware

Answer : Store service providers

How do you create a new test in Laravel?

1) php artisan make:test

2) artisan create:test

3) make:test

4) create:test

Answer : php artisan make:test

How can you access flash messages in Laravel?

1) session()->get()

2) session()->flash()

3) flash()

4) getFlash()

Answer : session()->get()

What is the purpose of the `resources/views` directory?

1) Store views

2) Store controllers

3) Store middleware

4) Store routes

Answer : Store views

How do you define a many-to-one relationship in Eloquent?

1) belongsTo()

2) hasMany()

3) hasOne()

4) oneToMany()

Answer : belongsTo()