Learn Laravel MCQs

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

What is the command to create a new Laravel project?

1) composer create-project --prefer-dist laravel/laravel projectName

2) laravel new projectName

3) php artisan new projectName

4) create-project laravel/laravel projectName

Answer : Option 1

How do you create a new database connection in Laravel?

1) Add it to config/database.php

2) Add it to .env file

3) Add it to config/app.php

4) Add it to app/Providers

Answer : Option 1

What is the purpose of the `config/cache.php` file?

1) Store cache configuration

2) Store application configuration

3) Store database configuration

4) Store routing configuration

Answer : Option 1

How can you send a raw SQL query in Laravel?

1) DB::raw()

2) DB::query()

3) DB::execute()

4) DB::run()

Answer : Option 1

What is the command to create a new event subscriber in Laravel?

1) php artisan make:subscriber

2) artisan create:subscriber

3) make:subscriber

4) create:subscriber

Answer : Option 1

How do you define a fallback route in Laravel?

1) Route::fallback()

2) Route::default()

3) Route::catchAll()

4) Route::fallbackRoute()

Answer : Option 1

How do you define an access control middleware in Laravel?

1) Route::middleware("auth")

2) Route::auth()

3) middleware("auth")

4) auth()->middleware()

Answer : Option 1

What is the command to create a new API controller in Laravel?

1) php artisan make:controller Api/ControllerName

2) artisan create:controller Api/ControllerName

3) make:controller Api/ControllerName

4) create:controller Api/ControllerName

Answer : Option 1

How can you generate a new migration file with a timestamp in Laravel?

1) php artisan make:migration create_table_name

2) php artisan make:migration create_table_name --timestamp

3) php artisan make:migration create_table_name --create

4) php artisan migrate:create

Answer : Option 1

What is the purpose of the `php artisan serve` command?

1) Run a local development server

2) Migrate the database

3) Clear cache

4) Install dependencies

Answer : Option 1