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 : request()->input()

What is the purpose of middleware in Laravel?

1) Routing

2) Handling requests

3) Authenticating users

4) All of the above

Answer : All of the above

Which database system is used by default in Laravel?

1) SQLite

2) MySQL

3) PostgreSQL

4) SQL Server

Answer : SQLite

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

1) hasMany()

2) belongsTo()

3) hasOne()

4) manyToMany()

Answer : hasMany()

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 : php artisan make:seeder

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 : Protects against CSRF

How do you define a resource route in Laravel?

1) Route::resource()

2) Route::route()

3) Route::controller()

4) Route::resourceRoute()

Answer : Route::resource()

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

1) json()

2) response()->json()

3) JSONResponse()

4) response()->responseJson()

Answer : response()->json()

What is the default template engine in Laravel?

1) Twig

2) Blade

3) Smarty

4) PHP

Answer : Blade

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 : php artisan make:middleware