Learn Laravel MCQs

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

What is the purpose of the `app/Http/Kernel.php` file?

1) Define middleware

2) Define routes

3) Define service providers

4) Define events

Answer : Option 1

How can you check if a user is authenticated in Laravel?

1) auth()->check()

2) isAuthenticated()

3) Auth::check()

4) user()->isAuthenticated()

Answer : Option 1

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

1) Store public assets

2) Store views

3) Store controllers

4) Store middleware

Answer : Option 1

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

1) morphedByMany()

2) belongsToMany()

3) hasMany()

4) morphToMany()

Answer : Option 1

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

1) php artisan make:seeder

2) artisan create:seeder

3) make:seeder

4) create:seeder

Answer : Option 1

How can you retrieve the current request URI in Laravel?

1) request()->getUri()

2) request()->url()

3) request()->path()

4) request()->getPath()

Answer : Option 1

What is the purpose of the `routes/web.php` file in Laravel?

1) Define API routes

2) Define web routes

3) Define console routes

4) Define middleware routes

Answer : Option 2

How do you use the `with` method in Eloquent?

1) Model::with()

2) Model::get()

3) Model::load()

4) Model::query()

Answer : Option 1

What is the command to generate a new resource in Laravel?

1) php artisan make:resource

2) artisan create:resource

3) make:resource

4) create:resource

Answer : Option 1

How do you access the authenticated user in Laravel?

1) auth()->user()

2) Auth::user()

3) user()

4) currentUser()

Answer : Option 1