Laravel Interview Question
Laravel Interview Question
1) What is Laravel?
Laravel is an open-source widely used PHP framework. The platform was intended
for the development of web application by using MVC architectural pattern.
Laravel is released under the MIT license.
The latest Laravel version is version 9, which was released on February 8, 2022.
3) Define composer.
6) What is a Route?
Most commonly, a route simply points to a method on a controller and also dictates
which HTTP methods are able to hit that URI.
Routes are stored inside files under the /routes folder inside the project’s root
directory. By default, there are a few different files corresponding to the different
“sides” of the application (“sides” comes from the hexagonal architecture
methodology).
App/: This is a source folder where our application code lives. All controllers,
policies, and models are inside this folder.
Config/: Holds the app’s configuration files. These are usually not modified
directly but instead, rely on the values set up in the .env (environment) file at the
root of the app.
Database/: Houses the database files, including migrations, seeds, and test
factories.
Laravel traits are a group of functions that you include within another class. A trait
is like an abstract class. You cannot instantiate directly, but its methods can be
used in concreate class.
13) Explain the concept of contracts in Laravel.
They are set of interfaces of Laravel framework. These contracts provide core
services. Contracts defined in Laravel include corresponding implementation of
framework.
You can register service providers in the config/app.php configuration file that
contains an array where you can mention the service provider class name.
Get method allows you to send a limited amount of data in the header. Post allows
you to send a large amount of data in the body.
An event is an occurrence or action that help you to subscribe and listen for events
that occur in Laravel application. Some of the events are fired automatically by
Laravel when any activity occurs.
Laravel has blade template engine to create dynamic layouts and increase
compiling tasks.
The framework helps you to make new tools by using LOC container.
Laravel offers a version control system that helps with simplified management of
migrations.
While processing a large amount of data, you can use the cursor method in order to
reduce memory usage.
26) List available types of relationships in Laravel Eloquent.
PostgreSQL
SQL Server
SQLite
MySQL
Laravel has helpers to generate URLs. This is helpful when you build link in your
templates and API response.
33) Which class is used to handle exceptions?
This function is used to dump contents of a variable to the browser. The full form
of dd is Dump and Die.
softDeletes(): It does not remove the data from the table. It is used to flag any
record as deleted.
41) How can you make real time sitemap.xml file in Laravel?
You can create all web pages of a website to tell the search engine about the
organizing site content. The crawlers of search engine read this file intelligently to
crawl a website.
It is a type of module or packages which are used to create fake data. This data can
be used for testing purpose.
Use hasTable() Laravel function to check the desired table is exists in the database
or not.
44) What is the significant difference between insert() and insertGetId() function in
Laravel?
Insert(): This function is simply used to insert a record into the database. It not
necessary that ID should be autoincremented.
InsertGetId(): This function also inserts a record into the table, but it is used when
the ID field is auto-increment.
Routing
Eloquent ORM
Middleware
Security
Caching
Blade Templating
Implicit Controllers help you to define a proper route to handle controller action.
You can define them in route.php file with Route:: controller() method.
In order to use a custom table, you can override the property of the protected
variable $table.
Controller: It is work as an interface between Model, and View. It is a way how the
user interacts with an application.
Cookies are small file sent from a particular website and stored on PC by user’s
browser while the user is browsing.
To create a connection with the database, you can use .env file.
RegisterController
LoginController
ResetPasswordController
ForgetPasswordController
Laravel guard is a special component that is used to find authenticated users. The
incoming requested is initially routed through this guard to validate credentials
entered by users. Guards are defined in ../config/auth.php file.
Collections is a wrapper class to work with arrays. Laravel Eloquent queries use a
set of the most common functions to return database result.
DB facade is used to run SQL queries like create, select, update, insert, and delete.
It allows routing all your application requests to the controller. Laravel routing
acknowledges and accepts a Uniform Resource Identifier with a closure.
Session is used to pass user information from one web page to another. Laravel
provides various drivers like a cookie, array, file, Memcached, and Redis to handle
session data.
Listeners are used to handling events and exceptions. The most common listener in
Laravel for login event is LoginListener.
Laravel Dusk is a tool which is used for testing JavaScript enabled applications. It
provides powerful, browser automation, and testing API.
Laravel developers can use make method to bind an interface to concreate class.
This method returns an instance of the class or interface. Laravel automatically
inject dependencies defined in class constructor.
All controllers and routes should return a response to be sent back to the web
browser. Laravel provides various ways to return this response. The most basic
response is returning a string from controller or route.
Laravel homestead is the official, disposable, and pre-packaged vagrant box that a
powerful development environment without installing HHVM, a web server, and
PHP on your computer.
A namespace allows a user to group the functions, classes, and constants under a
specific name.
Laravel Forge helps in organizing and designing a web application. Although the
manufacturers of the Laravel framework developed this toll, it can automate the
deployment of every web application that works on a PHP server.
Name route is a method generating routing path. The chaining of these routes can
be selected by applying the name method onto the description of route.
It is the method of converting text into a key that shows the original text. Laravel
uses the Hash facade to store the password securely in a hashed manner.
It is a process of transforming any message using some algorithms in such way that
the third user cannot read information. Encryption is quite helpful to protect your
sensitive information from an intruder.
To pass data to all views in Laravel use method called share(). This method takes
two arguments, key, and value.
Generally, share() method are called from boot method of Laravel application
service provider. A developer can use any service provider, AppServiceProvider,
or our own service provider.
Web.php is the public-facing “browser” based route. This route is the most
common and is what gets hit by the web browser. They run through the web
middleware group and also contain facilities for CSRF protection (which helps
defend against form-based malicious attacks and hacks) and generally contain a
degree of “state” (by this I mean they utilize sessions).