Learn Laravel MCQs

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

What is the role of the `Route::fallback()` method in Laravel?

1) Defines a route for undefined URLs

2) Specifies the default controller

3) Handles 404 errors

4) Redirects to the homepage

Answer : Option 3

Which command is used to optimize the performance of a Laravel application?

1) php artisan optimize

2) php artisan clear

3) php artisan cache:optimize

4) php artisan performance

Answer : Option 1

How do you specify default values for environment variables in Laravel?

1) env()

2) config()

3) request()

4) default()

Answer : Option 2

What is the role of Laravel’s `Authorization` feature?

1) Controlling access to specific actions

2) Managing authentication

3) Logging user activity

4) Defining routes

Answer : Option 1

How do you handle file downloads in Laravel?

1) Storage::download()

2) Storage::getFile()

3) Storage::load()

4) Storage::stream()

Answer : Option 1

Which method is used to add constraints to relationships in Laravel?

1) with()

2) has()

3) where()

4) join()

Answer : Option 2

What does the `compact()` function do in Laravel?

1) Creates an array from given variables

2) Compacts database records

3) Filters queries

4) Minimizes output

Answer : Option 1

How do you retrieve flash session data in Laravel?

1) session()->get()

2) session()->flash()

3) request()->session()

4) input()->session()

Answer : Option 3

Which Blade directive is used to display raw, unescaped data?

1) {{!! $variable !!}}

2) {{ $variable }}

3) @raw($variable)

4) @escape($variable)

Answer : Option 1

How do you retrieve query string values in Laravel?

1) request()->query()

2) input()

3) request()->getQuery()

4) url()->params()

Answer : Option 1