Home >> Interviews Q & A >> Top 50 Laravel Interview Questions

Top 50 Laravel Interview Questions

Laravel Interview Questions: Laravel is a free, open-source PHP web framework, created by Taylor Otwell.
Q-1 What is Laravel ?
Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern.
Q-2 What is Server Requirements for Laravel 5.6 ?
  • PHP >= 7.1.3
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
Q-3 How to Install Laravel via Composer ?
composer create-project --prefer-dist laravel/laravel myproject

For Other Info Please check official website of Laravel

Q-4 How to Install any Specific version of Laravel via Composer ?
//Composer Command To Install Laravel:
composer create-project --prefer-dist laravel/laravel ProjectName "VersionNo.*"

//Example: Install Laravel 5.4 using Composer
composer create-project --prefer-dist laravel/laravel blog "5.4.*"

For Other Info Please check official website of Laravel

Q-5 List benefits of using Laravel over other PHP frameworks ?

Reasons why Laravel is the best PHP framework:

  1. Artisan - A Command-Line Interface
  2. Migrations & Seeding
  3. Blade Template Engine
  4. Middleware - HTTP middleware provide a convenient mechanism for filtering HTTP requests entering your application.
  5. Eloquent ORM + Built-in Database Query Builder
  6. Routing (RESTful routing)
  7. Inbuilt packages - Authentication, Cashier, Scheduler, SSH, Socialite
  8. Security
  9. Unit Testing - Built-in unit testing and simply readable impressive syntax
  10. Caching - Laravel provides an expressive, unified API for various caching backends

Read more in detail about these

Q-6 List out some official packages provided by Laravel
Following are some official packages provided by Laravel

Laravel makes implementing authentication very simple. In fact, almost everything is configured for you out of the box.

//Make authorization views and scaffolding
php artisan make:auth
  1. In Short, Laravel provides Passport for API Authentication.
  2. Laravel Passport is an OAuth2 server and API authentication package that is simple to use

Laravel Cashier provides an expressive, fluent interface to Stripe’s and Braintree’s subscription billing services

  1. Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models.
  2. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records
  3. Currently, Scout ships with an Algolia driver; however, writing custom drivers is simple and you are free to extend Scout with your own search implementations.
  1. Laravel's Socialite package makes it simple to authenticate your users to social login
  2. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub and Bitbucket.
You may also like - Basic Laravel Interview Questions And Answers
Q-7 What is Lumen ?
  1. Lumen is a micro-framework provided by Laravel.
  2. It is developed by creator of Laravel Taylor Otwell.
  3. It is mostly used for creating RESTful API’s & microservices.
  4. Lumen is built on top components of Laravel.
Q-8 How to Install Lumen via Composer ?

Composer is PHP dependency manager used for installing dependencies of PHP applications.

composer create-project --prefer-dist laravel/lumen myproject
Q-9 What is php artisan ?
  1. Artisan is the command-line interface included with Laravel.
  2. It provides a number of helpful commands that can assist you while you build your application.
  3. To view a list of all available Artisan commands, you may use the list command:
  4. php artisan list //it will all commands
    php artisan --version	//to check current installed laravel version
Q-10 List mostly used artisan commands ?
  1. To view a list of all available Artisan commands, you may use the list command:
  2. php artisan list //it will all commands
    php artisan --version	//to check current installed laravel version
  3. Mostly used Artisan commands are:
  4. php artisan list //it will all commands
    php artisan --version	//to check current installed laravel version
    //Clear view caches
    php artisan view:clear
    //Clear cache
    php artisan cache:clear
    //Make authorization views and scaffolding
    php artisan make:auth
    //Make a new model
    php artisan make:model model-name
    //Make a new empty controller
    php artisan make:controller MyController

    Read more in details

Q-11 Explain Events in Laravel ?
  1. Laravel's events provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application
  2. Event classes are typically stored in the app/Events directory, while their listeners are stored in app/Listeners.
  3. Don't worry if you don't see these directories in your application, since they will be created for you as you generate events and listeners using Artisan console commands.
  4. A single event can have multiple listeners that do not depend on each other.
Q-12 How to turn off CRSF protection for all routes OR for some specific routes in Laravel ?
Disable CSRF Protection for all Routes In Laravel5
Remove or comment out this line in app\Http\Kernel.php


To turn off or diasble CRSF protection for some specific routes in Laravel

open "app/Http/Middleware/VerifyCsrfToken.php" file and add your routes in $except array.
namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
     * The URIs that should be excluded from CSRF verification.
     * @var array
    protected $except = [
Q-13 How can you change your default database type ?

By default Laravel is configured to use MySQL.

In order to change your default database edit your config/database.php

search for 'default' => env('DB_CONNECTION', 'mysql')
and change it to whatever you want (like 'default' => env('DB_CONNECTION', 'sqlite'))
Q-14 What is ORM ?

ORM: Object-relational Mapping (ORM) is a programming technique that help in converting data between incompatible type systems into object-oriented programming languages.

You may also like - Node Js Interview Questions and Answers
Q-15 Which ORM are being used by laravel ?

Eloquent ORM is being used by Laravel.

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.

All Eloquent models extend Illuminate\Database\Eloquent\Model class

Eloquent Model Examples:

The easiest way to create a model instance is using the make:model Artisan command
php artisan make:model User
If you would like to generate a database migration when you generate the model, you may use the --migration or -m option:
php artisan make:model User --migration

php artisan make:model User -m

Now look an Example:
namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
	//Your code 

Eloquent will assume the User model stores records in the users table

You may specify a custom table by defining a table property in your model, like below:

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
     * The table associated with the model.
     * @var string
    protected $table = 'my_tables';
Q-16 List types of relationships available in Laravel Eloquent?
  1. Eloquent relationships are defined as methods on your Eloquent model classes
  2. Relationships supported by Laravel Eloquent ORM:
    1. One To One - hasOne
    2. One To Many - hasMany
    3. One To Many(Inverse) - belongsTo
    4. Many To Many - belongsToMany
    5. Has Many Through - hasManyThrough
    6. Polymorphic Relations
    7. Many To Many Polymorphic Relations

Visit Official website of Laravel for Details

Q-17 Which Template Engine used by Laravel?

Blade is the simple, yet powerful templating engine provided with Laravel

Q-18 What is benefits of using "Blade" Template in Laravel?

Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views

In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application

Blade view files use the .blade.php file extension and are typically stored in the resources/views directory.

Visit Official website of Laravel for Details

Q-19 How to enable maintenance mode in Laravel 5 ?

When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a MaintenanceModeException will be thrown with a status code of 503.

You can enable maintenance mode in Laravel 5, simply by executing below command.

// Enable maintenance mode
php artisan down

// Disable maintenance mode
php artisan up
Q-20 What is the purpose of using dd() function in laravel ?

dd() – Stands for "Dump and Die"

Laravel's dd() is a helper function ,which will dump a variable's contents to the browser and halt further script execution.

Q-21 How to get current environment in Laravel 5 ?

$environment = App::environment();

Q-22 What is Middleware ?

Middleware provide a convenient mechanism for filtering HTTP requests entering your application.

Read more in details

Q-23 Explain Laravel service container ?
The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection.

Dependency injection is technique which means: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.

Almost all of your service container bindings will be registered within service providers

Dependency Injection Benefits:
  1. More Reusable Code
  2. More Testable Code
  3. More Readable Code
Q-24 What are service providers in laravel ?
  1. Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel's core services are bootstrapped via service providers.
  2. Bootstrapping mean registering things, including registering service container bindings, event listeners, middleware, and even routes. Service providers are the central place to configure your application.
Q-25 How do you register a Service Provider ?
  1. All service providers extend the Illuminate\Support\ServiceProvider class.
  2. Most service providers contain a register and a boot method.
  3. Within the register method, you should only bind things into the service container.
php artisan make:provider MyServiceProvider
Q-26 What are Laravel Facades ?

In Short, Facades provide a "static" interface to classes that are available in the application's service container.

All of Laravel's facades are defined in the Illuminate\Support\Facades namespace.

Facades have many benefits. They provide a short and memorable syntax that allows you to use Laravel's features without remembering long class names that must be injected or configured manually.

Facades Vs Helper Functions: There is absolutely no practical difference between facades and helper functions. Many of these helper functions perform the same function as a corresponding facade. For example, this facade call and helper call are equivalent:

return View::make('welcome');  // facade call

return view('welcome');	// helper call
Q-27 How to use custom table in Laravel Model ?

We can use custom table in Laravel by simply overriding protected $table property of Eloquent.

class Article extends Eloquent {
    protected $table="custom_table_name";
Q-28 What is Fillable Attribute in a Laravel Model ?

In eloquent ORM, $fillable is an array which contains all those fields of table which can be filled using mass-assignment.

Mass assignment, means to send an array to the model to directly create a new record in Database

class User extends Model {
    protected $fillable = ['name', 'email', 'mobile']; // All fields inside $fillable array can be mass-assign
Q-29 What is Guarded Attribute in a Laravel Model ?
Guarded is the reverse of fillable.

If fillable specifies which fields to be mass assigned, guarded specifies which fields are not mass assignable.

class User extends Model {
    protected $guarded = ['role']; // All fields inside the $guarded array is not mass-assignable

If you want to block all fields from being mass-assign you can just do this.

protected $guarded = ['*'];

$fillable serves as a "white list", $guarded functions like a black list. you should use either $fillable or $guarded.

Q-30 What are Closures in laravel ?

A Closure is an anonymous function. Closures are often used as a callback methods and can be used as a parameter in a function.

Q-31 What are Laravel Contracts ?
  1. Laravel's Contracts are a set of interfaces that define the core services provided by the framework.
  2. For example, a Illuminate\Contracts\Queue\Queue contract defines the methods needed for queueing jobs, while the Illuminate\Contracts\Mail\Mailer contract defines the methods needed for sending e-mail
  3. Each contract has a corresponding implementation provided by the framework.
Q-32 What are traits in Laravel ?

As of PHP 5.4, we now have a mechanism for reusing code, called Traits.

Q-33 How to get Logged in user info in Laravel ?

The laravel Auth Facade is used to get the autheticated user data as

use Illuminate\Support\Facades\Auth;

$user = Auth::user();
Q-34 How to enable query log in Laravel ?

Laravel can optionally log in memory all queries that have been run for the current request

//Enable query log

//See query log
$queries = DB::getQueryLog();

//Last executed query
$last_query = end($queries);
Q-35 Does Laravel support caching?
  1. Yes, Laravel supports popular caching mechanism like Memcached and Redis.
  2. By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the file system.
  3. For large projects it is recommended to use Memcached or Redis.
Q-36 What is Laravel Elixir ?
Q-37 What is Laravel Mix ?
Q-38 How can you display HTML with Blade in laravel ?
{!! $text !!}
Q-39 List out Databases Laravel supports ?

Currently, Laravel supports four databases:

  1. MySQL
  2. PostgreSQL
  3. SQLite
  4. SQL Server

you can use NoSQL databses with laravel by installing their packages.

Laravel doesn't support mongoDB out of the box, you'll have to install a third party package or create your own implementation. I'd suggest using https://github.com/jenssegers/laravel-mongodb , it seems a pretty popular package on packagist atleast. Or you could use the php mongodb class https://secure.php.net/manual/en/class.mongodb.php.

Q-40 In which language Laravel is written ?

Laravel is written in PHP.

Q-41 What are Bundles, Reverse Routing & IoC container ?
Q-42 How To Use Select Query In Laravel ?
Using Eloquent ORM:
$result = App\User::all(); // Find all records
$result = App\User::find(1); // Find by AutoIncrement ID
Using Query Builder:
$result = DB::table('users')->where('id', 1)->get(); // Find by ID
Q-43 How To Use Insert Query In Laravel ?
Using Eloquent ORM:
class UserController extends Controller
     * Create a new user instance.
     * @param  Request  $request
     * @return Response
    public function store(Request $request)
        $user = new User;
        $user->name = $request->name;
        $user->role = $request->role;
Using Query Builder:
$result = DB::table('users')->insert(
    ['name' => 'Full Stack Tutorials', 'role' => 'author']

//If the table has an auto-incrementing id, use the insertGetId method to insert a record and then retrieve the ID:
$id = DB::table('users')->insertGetId(
    ['name' => 'Full Stack Tutorials', 'role' => 'author']
Q-44 How To Use Update Query In Laravel ?
Using Eloquent ORM:
$result = User::where('id',1)->update(['name'=>'Full Stack Tutorials']);
Using Query Builder:
$result = DB::table('users')->where('id', 1)->update(['name' => 'Full Stack Tutorials']);
Q-45 How To Use Delete Query In Laravel ?
Using Eloquent ORM:
$result = User::where('id',$id)->delete();
Using Query Builder:
$result = DB::table('users')->where('id', $id)->delete();
Q-46 Is laravel application secure ?

Laravel is a development framework and, as such, it won't make your server more secure, just your application. Laravel features allow you to use everything securely. All the data is sanitized where needed unless you're using Laravel with raw queries.

Q-47 What are Accessors and Mutators in Eloquent and why should you use them ?

Laravel accessors and mutators are custom, user defined methods that allow you to format Eloquent attributes.

  1. Accessors:
    Accessors are used to format attributes when you retrieve them from the database
  2. Mutators:
    Mutators are used to format attributes before saving them into the database
Q-48 How do I perform dependency injection in Laravel ?
Q-49 How do I log an error ?

By default, Laravel is configured to create a log file for your application in the storage/logs directory.

Log files are in storage/logs/laravel.log, laravel.log is the default filename.

You may write information to the logs using the Log facade

namespace App\Http\Controllers;

use App\User;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;

class UserController extends Controller
     * Show the profile for the given user.
     * @param  int  $id
     * @return Response
    public function showProfile($id)
        Log::info('Showing user profile for user: '.$id);

        return view('user.profile', ['user' => User::findOrFail($id)]);

The logger provides the eight logging levels defined in RFC 5424: emergency, alert, critical, error, warning, notice, info and debug.

you can visit official website to read in more detail

Q-50 What's New in Laravel 5.8 ?

Laravel 5.8 is now released and has many improvements, addition and some breaking changes.

Major Upgrade or Breaking Changes:
  1. Caching TTL
  2. Deprecated Helper Functions
  3. Dotenv 3.0
  4. Carbon version 2
  5. Notifications Package
  6. Testing PHPUnit 8
  7. Password Length
  1. Error Page
  2. Artisan Call Improvements
  3. Email Validation
  4. Eloquent Resource Key Preservation
  5. Higher Order orWhere Eloquent Method
  6. JSON in MYSQL
  7. Correct Pluralisation
  8. Mock / Spy Testing Helper Methods
New Addition:
  1. Artisan Serve Improvements
  2. Auto-Discovery Of Model Policies
  3. HasOneThrough Relationship
  4. Token Guard Token Hashing
  5. Default Scheduler Timezone
  6. Multiple Broadcast Authentication Guards

Laravel 5.8 Latest Updates

Full Stack Tutorials

Author | Blogger @FullStackTutorials | View all articles