Learn Laravel MCQs

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

How do you add a database column to an existing migration in Laravel?

1) Schema::table("table_name", function($table) { $table->string("column_name"); })

2) Schema::addColumn("table_name", "column_name", "string")

3) Schema::modify("table_name")->add("column_name", "string")

4) Schema::update("table_name")->add("column_name", "string")

Answer : Option 1

How do you generate a new migration in Laravel?

1) php artisan make:migration migration_name

2) artisan create:migration migration_name

3) make:migration migration_name

4) create:migration migration_name

Answer : Option 1

What is the command to run unit tests in Laravel?

1) php artisan test

2) php artisan run:test

3) php artisan unit:test

4) php artisan phpunit

Answer : Option 1

How do you set environment variables in Laravel?

1) Using .env file

2) Using config/app.php

3) Using config/database.php

4) Using app/Http/Kernel.php

Answer : Option 1

What is the command to cache the configuration in Laravel?

1) php artisan config:cache

2) php artisan cache:config

3) php artisan config:store

4) php artisan cache:settings

Answer : Option 1

How do you define an API route in Laravel?

1) Route::get("/api/endpoint", "Controller@method")

2) Route::api("/api/endpoint", "Controller@method")

3) Route::define("/api/endpoint", "Controller@method")

4) Route::add("/api/endpoint", "Controller@method")

Answer : Option 1

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

1) Serve the application on a development server

2) Run database migrations

3) Clear application cache

4) Generate application key

Answer : Option 1

How do you create a new event in Laravel?

1) php artisan make:event EventName

2) artisan create:event EventName

3) make:event EventName

4) create:event EventName

Answer : Option 1