Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `app/Http/Kernel.php` file?
1) Register middleware
2) Define routes
3) Handle requests
4) Configure services
Answer : Register middleware
How do you define an API resource route with additional parameters?
1) Route::apiResource("name", "ControllerName")->parameters(["name" => "customName"])
2) Route::resource("name", "ControllerName")->parameters(["name" => "customName"])
3) Route::api("name", "ControllerName")->parameters(["name" => "customName"])
4) Route::addApiResource("name", "ControllerName")->parameters(["name" => "customName"])
Answer : Route::apiResource("name", "ControllerName")->parameters(["name" => "customName"])
What is the command to install a new Laravel package using Composer?
1) composer require package/name
2) composer install package/name
3) composer add package/name
4) composer create package/name
Answer : composer require package/name
How do you run the migrations in a specific database connection in Laravel?
1) php artisan migrate --database=connection_name
2) php artisan migrate:run --database=connection_name
3) php artisan migrate --conn=connection_name
4) php artisan migrate --connection=connection_name
Answer : php artisan migrate --database=connection_name
What is the command to create a new Laravel test case?
1) php artisan make:test TestName
2) artisan create:test TestName
3) make:test TestName
4) create:test TestName
Answer : php artisan make:test TestName
How do you create a soft delete in Eloquent?
1) use SoftDeletes;
2) use SoftDelete;
3) use Deletes;
4) use SoftDeleteTrait;
Answer : use SoftDeletes;
What is the purpose of the `routes/web.php` file?
1) Define web routes
2) Define API routes
3) Define console routes
4) Define middleware routes
Answer : Define web routes
How do you listen for events in Laravel?
1) Event::listen()
2) events()->listen()
3) Event::on()
4) Event::subscribe()
Answer : Event::listen()
What is the command to generate a new Laravel package?
1) php artisan make:package PackageName
2) artisan create:package PackageName
3) make:package PackageName
4) create:package PackageName
Answer : php artisan make:package PackageName
How do you handle file uploads in Laravel?
1) Request::file()
2) request()->file()
3) fileUpload()
4) uploads()->handle()
Answer : request()->file()