Learn Laravel MCQs

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

Which method is used to add pagination to an Eloquent query?

1) paginate()

2) getPaginated()

3) limit()

4) chunk()

Answer : Option 1

How do you define a database transaction in Laravel?

1) DB::transaction()

2) DB::beginTransaction()

3) DB::startTransaction()

4) DB::runTransaction()

Answer : Option 1

Which command is used to create a new policy in Laravel?

1) php artisan make:policy

2) php artisan create:policy

3) php artisan new:policy

4) php artisan generate:policy

Answer : Option 1

Which method is used to validate requests in Laravel?

1) validate()

2) request()

3) input()

4) authorize()

Answer : Option 1

How do you retrieve a specific route parameter in Laravel?

1) route()

2) request()->route()

3) input()

4) parameter()

Answer : Option 2

What is the purpose of the `Gate` facade in Laravel?

1) To authorize actions

2) To restrict access

3) To manage routes

4) To encrypt data

Answer : Option 3

How do you use the session facade to store data in Laravel?

1) Session::put()

2) Session::save()

3) Session::add()

4) Session::store()

Answer : Option 1

What does the `php artisan serve` command do in Laravel?

1) Starts the local development server

2) Compiles the code

3) Clears the cache

4) Runs the migrations

Answer : Option 1

Which method is used to retrieve a collection of models in Laravel?

1) all()

2) get()

3) find()

4) where()

Answer : Option 2

How do you share data across all views in Laravel?

1) View::share()

2) View::global()

3) Session::share()

4) Data::share()

Answer : Option 1