About Laravel

Laravel is created by Taylor Otwell for developing robust and secure web applications and APIs. It one of the most popular PHP framework which is based on MVC architecture. It was written in PHP & initially released in June 2011. the latest version of laravel is Laravel 8, released on 8 Sep 2020.

Laravel Interview Questions

1) What is Laravel?

Laravel is a PHP based web-framework for building high-end web applications using its significant and graceful syntaxes. It comes with a strong collection of tools and provides application architecture. Moreover, it includes various characteristics of technologies like ASP.NET MVC, CodeIgniter, Ruby on Rails and lot more. This framework is open source framework. Along with that security of the application is also Laravel take care of.

2) Enlist major features of Laravel Framework?

Here are some of the best features of PHP Laravel Framework which makes it popular among developers and businesses.

  1. Template Engine: Laravel framework is highly acknowledged for its built-in lightweight templates which can be used to create wonderful layouts using dynamic content seeding. In addition to this, it provides multiple widgets incorporating CSS and JS code with robust structures. Laravel templates are innovatively designed to create simple as well as complex layouts with distinctive sections.
  2. MVC Architecture Support: Laravel supports MVC architecture pattern which ensures separates business logic and presentation layers. MVC pattern of Laravel has a lot of built-in functions, improves application performance and increases security as well as scalability.
  3. Eloquent ORM (Object Relational Mapping): Laravel offers Eloquent Object Relational Mapping (ORM) which includes a simple PHP Active Record implementation. This allows web application developers to write database queries with PHP syntax rather than writing SQL code. An ORM is relatively faster than other PHP frameworks.
  4. Security: Laravel framework offers very strong web application security. It uses hashed and salted password mechanisms so the password would never be saved as plain text in the database. It also uses the “Bcrypt Hashing Algorithm” for generating an encrypted password. Additionally, this PHP web development framework uses prepared SQL statements that prevent SQL injection attacks.
  5. Artisan: Laravel framework offers a built-in command-line tool called Artisan which helps to automate the majority of tedious repetitive programming tasks. These artisans can also be utilized to create the database structure, a skeleton code, and manage migration so it is a pretty easy-to-manage database system.
  6. Libraries & Modular: Laravel comes with pre-installed Object-Oriented and Modular libraries which are not available in many other PHP frameworks. For example, an Authentication library which is easy-to-implement and has features such as checking active users, Bcrypt hashing, password reset, CSRF (Cross-site Request Forgery) protection, and encryption. Furthermore, this framework is divided into individual modules adopting modern PHP principles facilitating responsive and modular web application development.
  7. Database Migration System: Laravel migration system helps to expand the web application database structure without re-creating every time when there is a change in the code.

Because of this feature, the risk of losing data is very minimal. It not only offers the facility to change the database structure but also helps to do using PHP code instead of SQL.

3) What are server requirements for Laravel 6?

The Laravel framework has a few system requirements. All of these requirements are satisfied by the Laravel Homestead virtual machine, so it's highly recommended that you use Homestead as your local Laravel development environment.

However, if you are not using Homestead, you will need to make sure your server meets the following requirements:

  • PHP >= 7.2.0
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

4) What are pros and cons of using Laravel Framework?

There is no framework that is perfect. Every framework has its own Pros and Cons. And you can do anything in any of the modern frameworks.

Every framework provides some alternatives for its cons or some more pros along with some more cons.

If you are a PHP lover then Laravel is the best framework for you with the latest technologies.

Laravel Pros:

  1. Easy to learn: Although its documents are already simplest. The Best Laravel and PHP Screencasts makes it more convenient. Its documentation is also very beautiful.
  2. It is an MVC framework: It avoids silly traditional architecture where developers used to write all HTML and PHP code in the same file.
  3. Eloquent ORM support: Another service provided to abstract and automate the model part. Relationships and mapping of the database with our application with a simple convention over configuration technique.
  4. Template: Blade template engine gives an easy experience in adding logic in the HTML file. So easy to add new features without hacking the core.
  5. Routing: The easiest to manage and abstract way of routing. It just makes everything hassle-free and the abstraction provided takes out each and every complexity. It also including reverse routing.
  6. Queue management: To abstract the unnecessary tasks and get them queued behind the scenes and make user response time much faster.
  7. In-house support for Redis. It can also be extended to Memcached.
  8. Dependency Injection: Easy testing and automating dependency loading.
  9. Artisan: Making command-line apps in a moment.

Laravel Cons:

  1. Less inbuilt support: It is lightweight so it has less inbuilt support in comparison 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.
  2. Some classes are bit trickier: Laravel’s Core files are all within (at least) the Laravel namespace and not all of the files in core use a namespace slash ( a \ ) in front of a call to another core file, which makes extending some classes a bit trickier. This is not a huge issue and one, not every developer will need to worry about.

5) What is composer?

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 was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project.

6) What is lumen?

Lumen is a new project from Laravel creator Taylor Otwell. It's a "micro-framework", meaning it's a smaller, faster, leaner version of a full web application framework. PHP has two other popular micro-frameworks, Slim and Silex. Lumen has the same foundation as Laravel and many of the same components. But Lumen is built for microservices, not so much for user-facing applications (although it can be used for anything).

  • What’s it for?
  • Lumen is for projects and components that can benefit from the convenience and power of Laravel but can afford to sacrifice some configurability and flexibility in exchange for a speed boost.

7) How to install laravel via composer?

To install laravel using composer follow the steps below;

  1. Download and install Composer.
  2. Go inside the folder C:\xampp\htdocs>(if you are using xampp) or C:\wamp\www>(if you are using wamp).
  3. Open cmd/PowerShell & run the following commands :
    • composer global require "laravel/installer"
    • composer create-project laravel/laravel

      (after running this command a folder having name Laravel will be created there)

  4. Now go inside the Laravel folder and run php artisan serve command.
  5. After executing the last cmd, it will show a URL:; access the URL in a browser, which should reflect the will see the default webpage of Laravel.

8) Explain dependency injection in Laravel?

Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.

9) What are Facades in Laravel?

A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container's services.

10) What are Laravel Contract's?

Laravel's Contracts are a set of interfaces that define the core services provided by the framework.

For example, an 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 the email.

11) Whar are Bundles in Laravel?

Bundles are the heart of the improvements that were made in Laravel 3.0. They are a simple way to group code into convenient "bundles". A bundle can have it's own views, configuration, routes, migrations, tasks, and more.

A bundle could be everything from a database ORM to a robust authentication system.

12) Explain Laravel's service container?

The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection in Laravel Framework.

13) What is eloquent in Laravel?

Eloquent in Laravel is way of representing your database values with object you can easily use with your application.

14) Explain reverse routing in Laravel?

Laravel Reverse routing is the process of generating the URL based on name or symbol. It generates URL's based on route declarations. Reverse routing makes your application so much more flexible and helps the developer to write cleaner code in View. It defines a relationship between links and Laravel routes.

15) What are traits in Laravel?

Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

16) How to enable query log in Laravel?

Use the enableQueryLog method to enable query log in Laravel.



You can get an array of the executed queries by using the getQueryLog method:

$queries = DB::getQueryLog();

17) List some default packages provided by Laravel Framework?

Below are some official packages provided by Laravel:

  1. Dusk: Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your machine.
  2. Envoy: Laravel Envoy provides a clean, minimal syntax for defining common tasks you run on your remote servers. Using Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more. Currently, Envoy only supports the Mac and Linux operating systems.
  3. Horizon: Horizon provides a beautiful dashboard and code-driven configuration for your Laravel powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.
  4. Cashier: Laravel Cashier provides an expressive, fluent interface to Stripe's and Braintree subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.
  5. Passport: Laravel makes API authentication a breeze using Laravel Passport, which provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. Passport is built on top of the League OAuth2 server that is maintained by Alex Bilbie.
  6. Scout: Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.

18) How to turn off CRSF protection for specific route in Laravel?

To turn off CSRF protection in Laravel add following codes in "app/Http/Middleware/VerifyCsrfToken.php"

private $exceptUrls = ['controller/route1', 'controller/route2'];
 //modify this function
public function handle($request, Closure $next) {
 //add this condition foreach($this->exceptUrls as $route) {
 if ($request->is($route)) {
  return $next($request);
return parent::handle($request, $next);

19) Does Laravel support caching?

Laravel provides an expressive, unified API for various caching backends. The cache configuration is located at config/cache.php. In this file you may specify which cache driver you would like to be used by default throughout your application. Laravel supports popular caching backends like Memcached and Redis out of the box.

20) Explain Laravel?s Middleware?

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

For example,

Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.

Additional middleware can be written to perform a variety of tasks besides authentication. A CORS middleware might be responsible for adding the proper headers to all responses leaving your application. A logging middleware might log all incoming requests to your application.

21) How to use aggregate functions in Laravel?

Laravel provides a variety of aggregate functions such as max, min, count, avg, and sum. We can call any of these functions after constructing our query.

$users = DB::table(‘admin’)->count();
$maxComment = DB::table(‘blogs’)->max('comments');

22) What is IOC (Inversion of Control)?

In software engineering, inversion of control is a programming principle. IOC inverts the flow of control as compared to traditional control flow. In IOC, custom-written portions of a computer program receives the flow of control from a generic framework. A software architecture with this design inverts control as compared to traditional procedural programming: in traditional programming, the custom code that expresses the purpose of the program calls into reusable libraries to take care of generic tasks, but with inversion of control, it is the framework that calls into the custom, or task-specific, code.

23) How can you use custom table in Laravel Modal?

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

Below is sample uses

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

24) Enlist different types of relationships available in Laravel Eloquent?

Database tables are often related to one another.

For Example,

A blog post may have many comments, or an order could be related to the user who placed it. Eloquent makes managing and working with these relationships easy, and supports several different types of relationships:

  • One To One
  • One To Many
  • Many To Many
  • Has_many Through
  • One To One (Polymorphic)
  • One To Many (Polymorphic)
  • Many To Many (Polymorphic)

25) List some Aggregates methods provided by Laravel query builder?

The database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application, and works on all supported database systems.

Laravel query builder also provides a variety of aggregate methods, Such as:- count, max, min, avg, and sum.

26) How to check request is ajax or not in Laravel?

By using Ajax() method in Laravel, you can check request is ajax or not.

Laravel Request class has many methods to read HTTP requests for the current request. You can also check if the request is over https or request has JSON content type. You can use directly Request facade that grants you access to the current request or you can use an instance of Request Class.


public function index(Request $request)
		return response()->json(['status'=>'Ajax request']);
	 return response()->json(['status'=>'Http request']);
public function index() { if(Request::ajax())   { 
			return response()->json(['status'=>'Ajax request']);
		return response()->json(['status'=>'Http request']);

To determine if the request is over HTTPS :

if (Request::secure())

The Request class provides many methods to examine the HTTP requests for your application.

27) Explain Dependency Injection and its types?

In software engineering, dependency injection is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a service).

There are basically three types of dependency injection:

  1. Constructor injection: the dependencies are provided through a class constructor.
  2. Setter injection: the client exposes a setter method that the injector uses to inject the dependency.
  3. Interface injection: the dependency provides an injector method that will inject the dependency into any client passed to it. Clients must implement an interface that exposes a setter method that accepts the dependency.

28) What is HTTP middleware?

HTTP middleware provides a convenient mechanism for filtering HTTP requests entering your application.

For example,

Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.

29) What is migration in Laravel?

Migrations are a nice way to programmatically create and define databases.

You can use Artisan to create a migration class and in it define your database schema.

Laravel migration is a way that allows you to create a table in your database, without actually going to the database manager such as PHPMyAdmin or SQL lite or whatever is manage you.

30) How to get ip address of user in laravel?

The IP address of the user can be obtained in Laravel using \Request:: IP().

Below is an example :

protected function create(array $data) 
	return User::create([ 'role' => $data['role'], 
		'sex' => $data['gender'], 
		'fullname' => $data['fullname'],
		‘mobile' => $data['mobile'], 
		'mobile_prefix' => $data['mobile_prefix'],
		'email' => $data['email'],
		'co_name' => $data['co_name'], 
		'tel' => $data['tel'], 
		'tel_prefix' => $data['tel_prefix'], 
		'password' => bcrypt($data['password']), 
		'balance' => $data['balance'], 
		'last_ip' => \Request::ip(), 

Note:- Or you can also use request()->ip()

31) What are Laravel Collections?

A collection is a Laravel class that uses arrays internally and adds many features to them.

Please head towards this link for further explanation:- https://tutsforweb.com/15-laravel-collection-methods/

32) How to enable or disable maintenance mode in Laravel?

There are two ways to enable & disable maintenance mode in Laravel 5. Whenever your website is in maintenance mode, laravel returns a custom view that will be displayed for all requests. This makes it easy to "disable" your website or application while it is updating or when you are performing some maintenance.

To enable maintenance mode in laravel 5, execute below artisan command in your command line.

php artisan down

To disable maintenance mode in laravel 5, execute below artisan command in your command line.

php artsian up

33) How to pass CSRF token with ajax request?

You can add the Csrf-Token header with the headers option. As stated in the Play Framework 2.6 Documentation, you may set a ' Csrf-Token ' Header with the token generated by Play:

If you are making requests with AJAX, you can place the CSRF token in the HTML page, and then add it to the request using the Csrf-Token header.

34) What are Laravel service providers?

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 services providers.

But, what do we mean by "bootstrapped"?

In general, we mean registering things, including registering service container bindings, event listeners, middleware, and even routes. Service providers are the central place to configure your application.

35) How to call Stored Procedures in Laravel?

Stored procedures are handy for encapsulating database-intensive operations. Consider Stored Procedures as an API for your database.

To execute the stored procedure, Follow the steps below:

  • Step 1: Create a stored procedure.
  • Step 2: Include laravel’s DB class to the Controller / Model.
  • Step 3: Use DB:: select to call the Stored Procedure.

The first parameter uses call keyword to execute Stored Procedure and the second parameter takes data in an array format.

36) What is use of dd() in Laravel?

dd() is a helper function which is used to dump a variable's contents to the browser and stop the further script execution.

It stands for Dump and Die.


37) What are helpers in laravel? List few builtin helpers?

PHP helper functions that are used by Laravel are designed to speed up and homogenize repetitive tasks, and make your life that much easier. Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

action, decrypt, Str:: is, app_path, base_path, config_path, Arr:: sort, abort, redirect, auth, etc are few builtin helpers in Laravel.

38) What is PHP artisan? List some artisan commands you have used?

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.

Some of the artisan commands:

  • Listing All Available Commands

    To view a list of all available Artisan commands, you may use the list command:

    Php artisan list
  • Viewing The Help Screen For A Command

    Every command also includes a "help" screen which displays and describes the command's available arguments and options. To view a help screen, simply precede the name of the command with help:

    php artisan help
  • Specifying The Configuration Environment

    You may specify the configuration environment that should be used while running a command using the --env switch:

     php artisan migrate --env=local

39) How to use create / Read/ Remove session in laravel?

This can’t be explained here, please visit this link:- https://laravel.com/docs/5.8/session

40) How to get last inserted id using laravel query?

Whenever you perform an INSERT or UPDATE on a database table with an AUTO_INCREMENT column then you get the last insert id of last insert or update query. In PHP, you can use mysqli_insert_id to get the last inserted record id.

In laravel, when you go with DB query builder then you can use insertGetId() that will insert a record and then return last inserted record id.


1.public function getLastInsertedId()
3.    $id = DB::table('users')->insertGetId(
4.        ['email' => 'prayagchaudhary86@gmail.com', 'name' => 'Prayag Chaudhary']
5.    );
6.    print_r($id);

If you are inserting a record using Laravel Eloquent then you don't need to use insertGetId() function to get last inserted id. You can simply use a create a method to insert a new record into. The inserted model instance will be returned to you from the method.

public function getLastInsertedId()
2.   $user = User::create(['name'=>'Prayag Chaudhary','email'=>'prayagchaudhary86@gmail.com']);
3. print_r($user->id); 4.}

mysqli_insert_id() function will return zero if the table does not have an auto-incremented column so make sure the table must have a column with the AUTO_INCREMENT attribute.

41) What are cookies? How to create cookies in laravel?

Cookies:- A computer cookie is a small piece of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing.

Create Cookies:- Cookie can be created by a global cookie helper of Laravel. It is an instance of Symfony\Component\HttpFoundation\Cookie. The cookie can be attached to the response using the cookie() method. Create a response instance of Illuminate\Http\Response class to call the with cookie() method. The cookie generated by the Laravel is encrypted and signed and it can’t be modified or read by the client.

Here is a sample code with an explanation.

//Create a response instance
$response = new Illuminate\Http\Response('Hello World');
//Call the withCookie() method with the response method
$response->withCookie(cookie('name', 'value', $minutes));
//return the response
return $response;

Cookie() method will take 3 arguments. The first argument is the name of the cookie, the second argument is the value of the cookie and the third argument is the duration of the cookie after which the cookie will get deleted automatically.

A cookie can be set forever by using the forever method as shown in the below code.

$response->withCookie(cookie()->forever('name', 'value'));

42) What is Laravel Auth?

Authentication is the process of identifying user credentials. In web applications, authentication is managed by sessions that take the input parameters such as email or username and password, for user identification. If these parameters match, the user is said to be authenticated.

Laravel uses the following command to create forms and the associated controllers to perform authentication −

php artisan make:auth

The controller which is used for the authentication process is Auth\AuthController.

43) What is Attribute Casting and How does it work in Eloquent?

Attribute casting:- Casting a value means changing it to (or ensuring it is already) a particular type. Some types you might be familiar with are integer or boolean. Attribute casting is a feature of Eloquent models that allows you to set your model to automatically cast a particular attribute on your Eloquent model to a certain type.

Note:- You could do this in the past, but you would have to automatically define a mutator for each attribute; now you can do it automatically with a single configuration array.

That means if you store your data in a particular format in the database, and you want it to return in a different format, you can now cast it to the new format.

How does it work?

You cast attributes in Eloquent by adding a protected $casts array to your model.

 * The attributes that should be casted to native types.
 * @var array
protected $casts = [
    'is_admin' => 'boolean',

As you can see, each entry in the array has the property slug as the key and the cast type as the value. This $casts array is telling Eloquent: “Every time I access a property on this model named is_admin, please return it cast to type boolean.

44) What is Pusher in Laravel?

Pusher is a hosted service that makes it super-easy to add real-time data and functionality to web and mobile applications. Pusher sits as a real-time layer between your servers and your clients. Pusher maintains persistent connections to the clients - over WebSocket if possible and falling back to HTTP-based connectivity - so that as soon as your servers have new data that they want to push to the clients they can do, instantly via Pusher.

Pusher offers libraries to integrate into all the main runtimes and frameworks. PHP, Ruby, Python, Java, .NET, Go and Node on the server and JavaScript, Objective-C (iOS) and Java (Android) on the client.

45) How to create constants in laravel?

For most constants used globally across the application, storing them in config files is sufficient. It is also pretty simple to create a new file in the config directory.

Let's call it constants.php

In there you have to return an array of config values.

return [

'options' => [

'option_attachment' => '13',

'option_email' => '14',

'option_monetery' => '15',

'option_ratings' => '16',

'option_textarea' => '17',



And you can access them as follows:


// or if you want a specific one


46) How to remove /public from URL in laravel?

To remove Public from URL, follow the simple steps mentioned below:-

  1. Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root folder.

With the help of these steps, you can remove Public from URL

47) What is the difference between soft delete & delete in Laravel?

Deleting will remove the records in the database. To delete a model, call the delete method on a model instance:

$flight = App\Flight::find(1);$flight->delete();

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

For example (Migration class) :

public function up(){ Schema::create('flights', function(Blueprint $table) { 
$table->increments('id'); $table->softDeletes(); //creates the column "deleted_at"

If a model has a non-null deleted_at value, the model has been soft deleted. When querying a model that uses soft deletes, the "deleted" models will not be included in query results.


Using the restore method actually makes the deleted_at field NULL. To permanently delete a model use forcedelete method.

48) What is faker in Laravel? Why it is used?

Faker is a library that generates fake data for a variety of data types. Faker is shipped with Laravel by default so you don't have to install it as a third-party package.

Uses of Faker:- Faker can be used to generate the following data types:-

  • Numbers
  • Lorem Text
  • Person i.e. names, gender
  • Addresses
  • Phone Numbers
  • Companies
  • Text
  • DateTime
  • Internet i.e. domains, URLs, emails, etc.
  • User-Agents
  • Payments
  • Color
  • File
  • Images
  • UUID
  • Barcodes
  • Miscellaneous

49) What is laravel tinker?

Laravel artisan's tinker is a repl (read-eval-print loop). A repl translates to a read-eval-print-loop, and it is an interactive language shell. It takes in single user input, evaluates it, and returns the result to the user.

50) How to clear config cahe in Laravel?

We can use config:clear to clear the config cache of the Laravel application as shown below.

php artisan config:clear 

51) List different where Clauses available Laravel?

Where clause in Laravel is used to select rows from the database based on some condition.

where, whereOr, whereNotNull, whereNull, whereBetween are few Where clause types in Laravel.

52) How to check a table is exist or not in laravel?

We can check whether a table exists or not by typing the following command:


53) What are accessor and mutator in laravel?

In the Laravel, mutators and accessors allow you to alter data before it's saved to and fetched from a database. To be specific, the mutator allows you to alter data before it's saved to a database.

On the other hand, the accessor allows you to alter data after it's fetched from a database.

54) What are Laravel Closures?

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

55) What is Homebrew?

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple's macOS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user's taste.

56) What is Listeners in Laravel?

Laravel's events provide 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. 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.

57) What is Valet?

Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts file. You can even share your sites publicly using local tunnels.

58) What is Laravel Homestead?

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!

59) How to list all Vagrant Boxes?

You can use vagrant box list command to list all boxes that are installed into Vagrant.


vagrant box list

60) What is Contextual Binding?

Sometimes you may have two classes that utilize the same interface, but you wish to inject different implementations into each class.

For example,

two controllers may depend on different implementations of the Illuminate\Contracts\Filesystem\Filesystem contract.

61) What are Deferred Providers in laravel?

PHP file included with Laravel, you will see a provider's array. These are all of the service provider classes that will be loaded for your application. Of course, many of these are "deferred" providers, meaning they will not be loaded on every request, but only when the services they provide are actually needed.

62) What getFacadeAccessor method does?

Facades are another way to use classes without manually creating an object. They are just a shortcut to classes registered by Laravel container.

For example,


Makes absolutely the same as if you'd use the container:


So that's why, DB:: the facade is just a shortcut for app('db')->.

63) How to do 301 redirects in Laravel?

Whenever you are unsure, you can have a look at Laravel's API documentation with the source code. The Redirector class defines a status = 302 as a default value. You can define the status code with the to() method:

Route::get('foo', function(){ 
    return Redirect::to('/bar', 301); 

64) How to list all routes in Laravel?

Route::getRoutes() returns a RouteCollection. On each element, you can do a simple $route->getPath() to get the path of the current route.

Each protected parameter can get with a standard getter.

65) How to get current Url in Laravel?

Getting the current URL in Laravel is easy. Simply use the URL::current() helper.

66) How to register a middleware in Laravel?

If you want a middleware to run during every HTTP request to your application, list the middleware class in the $middleware property of your app/Http/Kernel.php class.

67) What are Macros in Laravel?

Macros are a way to reduce the lines of code a developer has to write and can be traditionally thought of as "shortcuts". Laravel generally uses macros to add, or inject, functionality into various classes at runtime.

68) What is Method Spoofing?

HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form.

The value sent with the _method field will be used as the HTTP request method.

For example:

<form action="/foo/bar" method="POST">
    <input type="hidden" name="_method" value="PUT">
    <input type="hidden" name="_token" value="">

69) What is the benefit of eager loading, when do you use it?

Eager Loading helps you to load all your needed entities at once; i.e., all your child entities will be loaded at a single database call. This can be achieved, using the Include method, which returns the related entities as a part of the query and a large amount of data is loaded at once.

70) What is Eloquent cursor()?

The cursor method allows you to iterate through your database records using a cursor, which will only execute a single query. When processing large amounts of data, the cursor method may be used to greatly reduce your memory usage.

1 comment(s) :

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.