Top Laravel interview questions

Mosharrf Hossain
Apr 7 · 3 min read

Q) What is composer in laravel?

Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It is also a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you

Q) What are traits in Laravel?

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.

trait Sharable {

public function share($item)
return 'share this item';


Q) Explain Bundles in Laravel?

In Laravel, bundles are also called packages.Packages are the primary way to extend the functionality of Laravel.

Q) Explain Middleware in Laravel?

As the name suggests, Middleware acts as a middleman between request and response. It is a type of filtering mechanism

Q) Explain Events in Laravel?

Laravel’s events provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application.Event classes are typically stored in the app/Events directory, while their listeners are stored in app/Listeners.

Q) What is PSR-4 in laravel?

This PSR(PHP Stander Recommendation) describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification. This PSR also describes where to place files that will be autoloaded according to the specification.

Q) What is Facade in laravel and how it is used? Explain?

The facade is a type of class which provides a static interface to services. Facade helps to access a service directly from the container. It is defined in the Illuminate\Support\Facades namespace. So that we can use it easily.

Q) What is ORM ?

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

Q) 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.

Q) Different kind of relationship in Eloquent ?

By Mahmoud Zalt

More at:

Q) How to use helper function in laravel ?

Step 1: Create one file named “helper.php” under “app” directory.

Step 2: Add “app/helper.php” file path in the “composer.json”.

Step 3: Updating the composer by executing the given command

composer dump-autoload

Q) What is database migration & seeder?

Migrations are like version control for your database, allowing 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.

Laravel includes a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UsersTableSeeder, etc.

Q) Soft Delete In Model Relationship

In addition to actually removing records from your database, Eloquent can also “soft delete” models. When models are soft deleted, they are not actually removed from your database. Instead, a deleted_at attribute is set on the model and inserted into the database.

Use this soft deletes by adding this command in model:

class Contents extends Eloquent {

use SoftDeletes;

protected $dates = ['deleted_at'];


Q) What are CSRF token in Laravel?

CSRF( cross-site request forgery) token prevents Cross-Site attack by comparing cookie token with server token.

Q) How to disabled CSRF token in Laravel?

  1. In App\Http\Middleware\VerifyCsrfToken and add your own routes name in protected
$except = [] array.

2. Open your app\Http\Kernel.php file and scroll downward to MiddlewareGroups and comment this line:


Reference from:


Mh Mohon

This is My blog

Mosharrf Hossain

Written by

Mh Mohon

Mh Mohon

This is My blog