Learn Laravel MCQs

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

How do you access a request input in Laravel?

1) request()->input()

2) request()->get()

3) Input::get()

4) input()

Answer : Option 1

What is the purpose of middleware in Laravel?

1) Routing

2) Handling requests

3) Authenticating users

4) All of the above

Answer : Option 4

Which database system is used by default in Laravel?

1) SQLite

2) MySQL

3) PostgreSQL

4) SQL Server

Answer : Option 1

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

1) hasMany()

2) belongsTo()

3) hasOne()

4) manyToMany()

Answer : Option 1

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

1) php artisan make:seeder

2) php artisan create:seeder

3) make:seeder

4) artisan make:seeder

Answer : Option 1

What is the purpose of the `@csrf` directive in Blade?

1) Protects against XSS

2) Protects against CSRF

3) Validates inputs

4) Encrypts data

Answer : Option 2

How do you define a resource route in Laravel?

1) Route::resource()

2) Route::route()

3) Route::controller()

4) Route::resourceRoute()

Answer : Option 1

Which function is used to return a JSON response in Laravel?

1) json()

2) response()->json()

3) JSONResponse()

4) response()->responseJson()

Answer : Option 1

What is the default template engine in Laravel?

1) Twig

2) Blade

3) Smarty

4) PHP

Answer : Option 2

How do you add a new middleware in Laravel?

1) php artisan make:middleware

2) artisan make:middleware

3) make:middleware

4) create:middleware

Answer : Option 1