What is Laravel?

Laravel is an MIT license open source “PHP framework” based on the 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. Due to MIT’s license, its source code is hosted on GitHub. It is a reliable PHP framework as it follows expressive and accurate language rules.

What is Composer?

It is an application-level package manager for PHP. It provides a standard format for managing PHP software dependencies and libraries.

What is HTTP middleware?

HTTP middleware is a technique for filtering HTTP requests. Laravel includes a middleware that checks whether the application user is authenticated or not.

To create a new middleware, use the make:middleware Artisan command:

php artisan make:middleware MiddlewareName

What are Events in Laravel?

An event is an action or occurrence recognized by a program that may be handled by the program or code. Laravel events provide 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 the app/Listeners of your application.

What are the validations in Laravel?

Validations are approaches that Laravel uses to validate the incoming data within the application.

They are a handy way to ensure that data is in a clean and expected format before it gets entered into the database. Laravel consists of several different ways to validate the incoming data of the application. By default, the base controller class of Laravel uses a ValidatesRequests trait to validate all the incoming HTTP requests with the help of powerful validation rules.

Laravel validation Example:-

$validate_data = $request->validate([
            'name' => 'required|max:255',
            'user_name' => 'required|alpha_num|max:255',
            'user_age' => 'required|numeric',

What are the main features of Laravel?

Some of the main features of Laravel are:-

  • Eloquent ORM
  • Query builder
  • Reverse Routing
  • Restful Controllers
  • Migrations
  • Database Seeding
  • Unit Testing
  • Homestead

How to install Laravel via composer?

You can install Laravel via composer by running the below command.

composer create-project laravel/laravel application-name

What is Eloquent ORM?

Eloquent ORM (Object-Relational Mapping) is one of the main features of the Laravel framework. It may be defined as an advanced PHP implementation of the active record pattern.

Active record pattern is an architectural pattern that is found in software. It is responsible for keeping in-memory object data in relational databases

Eloquent ORM is also responsible for providing the internal methods at the same time when enforcing constraints on the relationship between database objects. Eloquent ORM represents database tables as classes, with their object instances tied to single table rows while following the active record pattern.

What is Query Builder in Laravel?

Laravel’s Query Builder provides more direct access to the database, an alternative to the Eloquent ORM. It doesn’t require SQL queries to be written directly. Instead, it offers a set of classes and methods which are capable of building queries programmatically. It also allows specific caching of the results of the executed queries.

How to clear cache in Laravel?

The syntax to clear cache in Laravel is given below:

  • php artisan cache:clear
  • php artisan config:clear
  • php artisan optimize:clear

Name aggregates methods of the query builder.

Aggregates methods of query builder are:

1) max()

2) min()

3) sum()

4) avg()

5) count()

What is a Route?

A route is basically an endpoint specified by a URI (Uniform Resource Identifier). It acts as a pointer in the Laravel application.

Most commonly, a route simply points to a method on a controller and also dictates which HTTP methods are able to hit that URI.

Why use Route?

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” come from the hexagonal architecture methodology).

Explain Migrations in Laravel

Laravel Migrations are like version control for the database, allowing a team to easily modify and share the application’s database schema. Migrations are typically paired with Laravel’s schema builder to easily build the application’s database schema.