Laravel Interview Questions
Tags: laravel, interview, questions
Published: 2018-06-17 15:43:13

---
title: Laravel Interview Questions
published: true
description: Laravel is free open source “PHP framework” based on MVC design pattern. It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that helps in creating a wonderful web application easily and quickly.
tags: Laravel, interview, Questions 
---
Laravel is free open source “PHP framework” based on MVC design pattern.
It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that helps in creating a wonderful web application easily and quickly.
Many companies looking for developers who have knowledge of Laravel Framework. In this article, you can read few best interview Questions on Laravel Framework.

<h2>Top 30 Laravel interview questions and answers.</h2>
Below is the list of latest Laravel interview questions and answers.
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-is-laravel/">1. What is Laravel?</a></p>

<div class="blog_post_content">

Laravel is free open source “PHP framework” based on MVC design pattern.
It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that helps in creating a wonderful web application easily and quickly.

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/pros-cons-using-laravel-framework/">2. What are pros and cons of using Laravel Framework?</a></p>

<div class="blog_post_content">
<h5>Pros of using Laravel Framework</h5>
<ol>
 	<li>Laravel framework has in-built lightweight blade template engine to speed up compiling task and create layouts with dynamic content easily.</li>
 	<li>Hassles code reusability.</li>
 	<li>Eloquent ORM with PHP active record implementation</li>
 	<li>Built in command line tool "Artisan" for creating a code skeleton , database structure and build their migration</li>
</ol>
<h5>Cons of using laravel Framework</h5>
<ol>
 	<li>Development process requires you to work with standards and should have real understanding of programming</li>
 	<li>Laravel is new framework and composer is not so strong in compare to <strong>npm (for node.js)</strong>, <strong>ruby gems</strong> and<strong> python pip</strong>.</li>
 	<li>Development in laravel is not so fast in compare to ruby on rails.</li>
 	<li>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</li>
</ol>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-events-laravel/">3. Explain Events in laravel ?</a></p>

<div class="blog_post_content">

An event is an action or occurrence recognized by a program that may be handled by the program or code. Laravel events provides a simple observer implementation, that allowing you to subscribe and listen for various events/actions that occur in your application.

All Event classes are generally stored in the app/Events directory, while their listeners are stored in app/Listeners of your application.

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-validations-laravel/">4. Explain validations in laravel?</a></p>

<div class="blog_post_content">

In Programming validations are a handy way to ensure that your data is always in a clean and expected format before it gets into your database. Laravel provides several different ways to validate your application incoming data.By default Laravel’s base controller class uses a <strong>ValidatesRequests</strong> <strong>trait</strong> which provides a convenient method to validate all incoming HTTP requests coming from client.You can also validate data in laravel by creating Form Request.
<a href="https://laravel.com/docs/5.4/validation" target="_blank">click here</a> read more about data validations in Laravel.

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/install-laravel-via-composer/">5. How to install laravel via composer ?</a></p>

<div class="blog_post_content">

You can install Laravel via composer by running below command.
<pre><code>
composer create-project laravel/laravel your-project-name version

Also Read <strong><a href="https://www.onlineinterviewquestions.com/blog/core-php-interview-questions-2018/">Core PHP Interview Questions and Answers for 2018</a></strong></code></pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/list-features-laravel-5-0/">6. List some features of laravel 5.0 ?</a></p>

<div class="blog_post_content">
<ul>
 	<li>Inbuilt CRSF (<a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">cross-site request forgery</a> ) Protection.</li>
 	<li>Inbuilt paginations</li>
 	<li><a href="https://www.laravelinterviewquestions.com/2017/03/what-is-reverse-routing-in-laravel.html" target="_blank">Reverse Routing</a></li>
 	<li>Query builder</li>
 	<li>Route caching</li>
 	<li>Database Migration</li>
 	<li>IOC (Inverse of Control) Container Or service container.</li>
</ul>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/php-artisan-list-artisan-commands/">7. What is PHP artisan. List out some artisan commands ?</a></p>

<div class="blog_post_content">

<strong>PHP artisan</strong> 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:-
<ul>
 	<li>php artisan list</li>
 	<li>php artisan help</li>
 	<li>php artisan tinker</li>
 	<li>php artisan make</li>
 	<li>php artisan –versian</li>
 	<li>php artisan make model model_name</li>
 	<li>php artisan make controller controller_name</li>
</ul>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/list-default-packages-provided-laravel-5-4/">8. List some default packages provided by Laravel 5.4 ?</a></p>

<div class="blog_post_content">

Below are list of some official/ default packages provided by Laravel 5.4
<ul>
 	<li>Cashier</li>
 	<li>Envoy</li>
 	<li>Passport</li>
 	<li>Scout</li>
 	<li>Socialite</li>
</ul>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/named-routes-laravel/">9. What are named routes in Laravel?</a></p>

<div class="blog_post_content">

<strong>Named routing</strong> is another amazing feature of Laravel framework. Named routes allow referring to routes when generating redirects or Url’s more comfortably.
<strong>You can specify named routes by chaining the name method onto the route definition:</strong>
<pre><code>
Route::get('user/profile', function () {
    //
})-&gt;name('profile');

</code>
<strong>You can specify route names for controller actions:</strong>
<code>
Route::get('user/profile', 'UserController@showProfile')-&gt;name('profile');
</code>

<strong>Once you have assigned a name to your routes, you may use the route's name when generating URLs or redirects via the global route function:</strong>
<code>
// Generating URLs...
$url = route('profile');

// Generating Redirects...
return redirect()-&gt;route('profile');
</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/database-migration-create-migration-via-artisan/">10. What is database migration. How to create migration via artisan ?</a></p>

<div class="blog_post_content">

<strong>Migrations</strong> 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.
<pre><code>// creating Migration
php artisan make:migration create_users_table</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-are-service-providers/">11. What are service providers ?</a></p>

<div class="blog_post_content">

<strong>Service Providers</strong> 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 <a href="https://laravel.com/docs/5.4/providers" target="_blank">here</a>

<strong>Read Latest Codeigniter interview questions 2018.</strong>

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-laravels-service-container/">12. Explain Laravel’s service container ?</a></p>

<div class="blog_post_content">

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

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-is-composer/">13. What is composer ?</a></p>

<div class="blog_post_content">

<strong>Composer </strong>is a tool for managing dependency in PHP. It allows you to declare the libraries on which your project depends on and will manage (install/update) them for you.
<strong>Laravel </strong>utilizes Composer to manage its dependencies.

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/dependency-injection-laravel/">14. What is dependency injection in Laravel ?</a></p>

<div class="blog_post_content">In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client’s state.[1] Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.
source(<a href="https://en.wikipedia.org/wiki/Dependency_injection" target="_blank">https://en.wikipedia.org/wiki/Dependency_injection</a>).
You can do dependency injection via Constructor, setter and property injection.</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-are-laravel-contracts/">15. What are Laravel Contract’s ?</a></p>

<div class="blog_post_content">

Laravel’s Contracts are nothing but a set of interfaces that define the core services provided by the Laravel framework.
<a href="https://laravel.com/docs/5.4/contracts" target="_blank">Read more about laravel Contract’s</a>

</div>
Read Latest <strong><a href="https://www.onlineinterviewquestions.com/symfony-interview-questions/">Symfony interview questions</a></strong>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-facades-laravel/">16. Explain Facades in Laravel ?</a></p>

<div class="blog_post_content">

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:
<pre><code>
use Illuminate\Support\Facades\Cache;

Route::get('/cache', function () {
    return Cache::get('key');
});
</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-are-laravel-eloquent/">17. What are Laravel eloquent?</a></p>

<div class="blog_post_content">

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.
<pre><code>
// Querying or finding records from products table where tag is 'new'
$products= Product::where('tag','new');
// Inserting new record 
 $product =new Product;
 $product-&gt;title="Iphone 7";
 $product-&gt;price="$700";
 $product-&gt;tag='iphone';
 $product-&gt;save();
</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/enable-query-log-laravel/">18. How to enable query log in Laravel ?</a></p>

<div class="blog_post_content">

Use the <strong>enableQueryLog</strong> method to enable query log in Laravel
<pre><code>
DB::connection()-&gt;enableQueryLog(); 
You can get array of the executed queries by using getQueryLog method:
$queries = DB::getQueryLog();
</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/reverse-routing-laravel/">19. What is reverse routing in Laravel?</a></p>

<div class="blog_post_content">

Laravel reverse routing is generating URL’s based on route declarations.Reverse routing makes your application so much more flexible.It defines a relationship between links and Laravel routes.When a link is created by using names of existing routes, appropriate Uri’s are created automatically by Laravel. Here is an example of reverse routing.

// route declaration
<strong>Route::get(‘login’, ‘users@login’);</strong>

Using reverse routing we can create a link to it and pass in any parameters that we have defined. Optional parameters, if not supplied, are removed from the generated link.

<strong>{{ HTML::link_to_action(‘users@login’) }}</strong>

It will automatically generates a Url like http://xyz.com/login in view.

</div>
<strong><a href="https://www.onlineinterviewquestions.com/core-php-interview-questions/">Read 40 Best PHP Interview Questions 2018</a></strong>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/turn-off-crsf-protection-specific-route-laravel/">20. How to turn off CRSF protection for specific route in Laravel?</a></p>

<div class="blog_post_content">

To turn off CRSF protection in Laravel add following codes in “app/Http/Middleware/VerifyCsrfToken.php”
<pre><code> 
//add an array of Routes to skip CSRF check
private $exceptUrls = ['controller/route1', 'controller/route2'];
 //modify this function
public function handle($request, Closure $next) {
 //add this condition foreach($this-&gt;exceptUrls as $route) {
 if ($request-&gt;is($route)) {
  return $next($request);
 }
}
return parent::handle($request, $next);
} </code></pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-are-traits-in-laravel/">21. What are traits in Laravel?</a></p>

<div class="blog_post_content">

PHP Traits are simply a group of methods that you want include within another class. A Trait, like an abstract class cannot be instantiated by itself.Trait are created to reduce the limitations of single inheritance in PHP by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

Here is an example of trait.
<pre><code>trait Sharable {
 
  public function share($item)
  {
    return 'share this item';
  }
 
}
<strong>You could then include this Trait within other classes like this:</strong>

class Post {
 
  use Sharable;
 
}
 
class Comment {
 
  use Sharable;
 
}
<strong>Now if you were to create new objects out of these classes you would find that they both have the share() method available:</strong>
$post = new Post;
echo $post-&gt;share(''); // 'share this item' 
 
$comment = new Comment;
echo $comment-&gt;share(''); // 'share this item'</code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/laravel-support-caching/">22. Does Laravel support caching?</a></p>

<div class="blog_post_content">

Yes, Laravel supports popular caching backends like <strong>Memcached </strong>and <strong>Redis</strong>.
By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the file system.For large projects, it is recommended to use Memcached or Redis.

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-laravels-middleware/">23. Explain Laravel’s Middleware?</a></p>

<div class="blog_post_content">

As the name suggests, Middleware acts as a middleman between request and response. It is a type of filtering mechanism. For example, Laravel includes a middleware that verifies whether the user of the application is authenticated or not. If the user is authenticated, he will be redirected to the home page otherwise, he will be redirected to the login page.

There are two types of Middleware in Laravel.
Global Middleware: will run on every HTTP request of the application.
<strong>Route Middleware</strong>: will be assigned to a specific route.
<a href="https://laravel.com/docs/5.4/middleware" target="_blank">Read more about Laravel middlewares</a>

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/what-is-lumen/">24. What is Lumen?</a></p>

<div class="blog_post_content">

<strong>Lumen</strong> 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
<pre><code>composer create-project --prefer-dist laravel/lumen blog</code></pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/explain-bundles-laravel/">25. Explain Bundles in Laravel?</a></p>

<div class="blog_post_content">

In Laravel, bundles are also called packages.Packages are the primary way to extend the functionality of Laravel. Packages might be anything from a great way to work with dates like Carbon, or an entire BDD testing framework like Behat.In Laravel, you can create your custom packages too.You can read more about packages from <a href="https://laravel.com/docs/5.4/packages" target="_blank">here</a>

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/use-custom-table-laravel-modal/">26. How to use custom table in Laravel Modal ?</a></p>

<div class="blog_post_content">

You can use custom table in Laravel by overriding protected $table property of Eloquent.
<pre><code>
Below is sample uses

class User extends Eloquent{
 protected $table="my_user_table";

} </code>
</pre>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/list-types-relationships-available-laravel-eloquent/">27. List types of relationships available in Laravel Eloquent?</a></p>

<div class="blog_post_content">

Below are types of relationships supported by Laravel Eloquent ORM.
<ul>
 	<li>One To One</li>
 	<li>One To Many</li>
 	<li>One To Many (Inverse)</li>
 	<li>Many To Many</li>
 	<li>Has Many Through</li>
 	<li>Polymorphic Relations</li>
 	<li>Many To Many Polymorphic Relations</li>
</ul>
You can read more about relationships in Laravel Eloquent from <a href="https://laravel.com/docs/5.4/eloquent-relationships" target="_blank">here</a>

</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/why-are-migrations-necessary/">28. Why are migrations necessary?</a></p>

<div class="blog_post_content">

Migrations are necessary because:
<ul>
 	<li>Without migrations, database consistency when sharing an app is almost impossible, especially as more and more people collaborate on the web app.</li>
 	<li>Your production database needs to be synced as well.</li>
</ul>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/provide-system-requirements-installation-laravel-5-4/">29. Provide System requirements for installation of Laravel 5.4 ?</a></p>

<div class="blog_post_content">

In order to install laravel,make sure your server meets the following requirements:
<ul>
 	<li>PHP &gt;= 5.6.4</li>
 	<li>OpenSSL PHP Extension</li>
 	<li>PDO PHP Extension</li>
 	<li>Mbstring PHP Extension</li>
 	<li>Tokenizer PHP Extension</li>
 	<li>XML PHP Extension</li>
</ul>
</div>
<p class="questions"><a href="https://www.onlineinterviewquestions.com/list-aggregates-methods-provided-query-builder-laravel/">30. List some Aggregates methods provided by query builder in Laravel ?</a></p>

<div class="blog_post_content">
<ul>
 	<li>count()</li>
 	<li>max()</li>
 	<li>min()</li>
 	<li>avg()</li>
 	<li>sum()</li>
</ul>
Also Read <a href="https://www.onlineinterviewquestions.com/laravel-interview-questions-and-answers/"><strong>Laravel 5 interview questions 2018</strong></a>

</div>