Laravel interview questions

Laravel interview questions Download Laravel interview questions PDF

Laravel interview questions

Migrations are like version control for your database, that’s allow your team to easily modify and share the application’s database schema. Migrations are typically paired with Laravel’s schema builder to easily build your application’s database schema.

Use below commands to create migration data via artisan.

// creating Migration
php artisan make:migration create_users_table

You can install Laravel via composer by running below command.

composer create-project laravel/laravel your-project-name version

Also Read Core PHP Interview Questions and Answers for 2018

PHP artisan is the command line interface/tool included with Laravel. It provides a number of helpful commands that can help you while you build your application easily. Here are the list of some artisan command:-

  • php artisan list
  • php artisan help
  • php artisan tinker
  • php artisan make
  • php artisan –versian
  • php artisan make model model_name
  • php artisan make controller controller_name

One of the most powerful feature of Laravel is its Service Container. It is a powerful tool for resolving class dependencies and performing dependency injection in Laravel.
Dependency injection is a fancy phrase that essentially means class dependencies are “injected” into the class via the constructor or, in some cases, “setter” methods.

Below are list of some official/ default packages provided by Laravel 5.6

  • Cashier
  • Envoy
  • Passport
  • Scout
  • Socialite
  • Horizon

Laravel’s Eloquent ORM is simple Active Record implementation for working with your database. Laravel provide many different ways to interact with your database, Eloquent is most notable of them. Each database table has a corresponding “Model” which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

Below is sample usage for querying and inserting new records in Database with Eloquent.


// Querying or finding records from products table where tag is 'new'
$products= Product::where('tag','new');
// Inserting new record 
 $product =new Product;
 $product->title="Iphone 7";
 $product->price="$700";
 $product->tag='iphone';
 $product->save();
Pros of using Laravel Framework
  1. Laravel framework has in-built lightweight blade template engine to speed up compiling task and create layouts with dynamic content easily.
  2. Hassles code reusability.
  3. Eloquent ORM with PHP active record implementation
  4. Built in command line tool “Artisan” for creating a code skeleton , database structure and build their migration
Cons of using laravel Framework
  1. Development process requires you to work with standards and should have real understanding of programming
  2. Laravel is new framework and composer is not so strong in compare to npm (for node.js)ruby gems and python pip.
  3. Development in laravel is not so fast in compare to ruby on rails.
  4. Laravel is lightweight so it has less inbuilt support in compare to django and rails. But this problem can be solved by integrating third party tools, but for large and very custom websites it may be a tedious task

Below are types of relationships supported by Laravel Eloquent ORM.

  • One To One
  • One To Many
  • One To Many (Inverse)
  • Many To Many
  • Has Many Through
  • Polymorphic Relations
  • Many To Many Polymorphic Relations

You can read more about relationships in Laravel Eloquent from here

Laravel’s Contracts are nothing but a set of interfaces that define the core services provided by the Laravel framework.
Read more about laravel Contract’s

Service Providers are central place where all laravel application is bootstrapped . Your application as well all Laravel core services are also bootstrapped by service providers.
All service providers extend the Illuminate\Support\ServiceProvider class. Most service providers contain a register and a boot method. Within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.
You can read more about service provider from here

Laravel Facades provides a static like an interface to classes that are available in the application’s service container. Laravel self-ships with many facades which provide access to almost all features of Laravel ’s. Laravel facades serve as “static proxies” to underlying classes in the service container and provide benefits of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods of classes. All of Laravel’s facades are defined in the Illuminate\Support\Facades namespace. You can easily access a facade like so:


use Illuminate\Support\Facades\Cache;

Route::get('/cache', function () {
    return Cache::get('key');
});

Lumen is PHP micro-framework that built on Laravel’s top components.It is created by Taylor Otwell. It is perfect option for building Laravel based micro-services and fast REST API’s. It’s one of the fastest micro-frameworks available.
You can install Lumen using composer by running below command

composer create-project --prefer-dist laravel/lumen blog

Migrations are necessary because:

  • Without migrations, database consistency when sharing an app is almost impossible, especially as more and more people collaborate on the web app.
  • Your production database needs to be synced as well.