Laravel

Recently I wrote an article on the framework Laravel.Let me wrap up the main contents of the article here.

What is Laravel ?

Laravel is one of the best open source PHP web framework.It is an elegant  and comfortable framework to work on.It has a very neat syntax and makes web development easier.The prerequisite to work on Laravel is the basic knowledge in PHP. It follows MVC (Model View Controller) Architecture.It was created by Taylor Otwell in 2011.

Key Features:

Laravel holds the following key features which make it a flexible framework.

Routing system-It automatically create links to the named routes and insert the correct URI. A directory(where all routes are specified) is created.If a file text.php is added.It can be accessed by browsing to ‘localhost/directory/text.php.

Unit testing-It runs many tests to ensure that new changes are updated correctly.It is easy to write unit-tests for the own code.

View composers-These are class methods that are called when a view is returned.

Bundles-It provides a modular packaging system with many features and add-ons to the application.

Composer-This is a dependency manager to add framework-agnostic and Laravel-specific PHP packages available from the Packagist repository.

Automatic pagination-Automatic pagination simplifies the task of implementing pagination, replacing the usual manual implementation approaches with automated methods.

Form request -It is a special class for validating and authorizing form submissions.

Database seeding -Updating database tables with selected default data.

Migrations-Adding the changes of the application’s codebase in the database layout.

Authentication-It contains the ready to use inbuilt authentication system. You just need to configure database migrations, models, controllers and views to make the system work.

Restful controllers – It allows you to create methods directly from your controller which gets automatically mapped to your routes.

Query builder- Laravel’s query builder provides a set of classes and methods capable of building queries programmatically.

Controller method injection-Dependencies can be injected directly to the methods.There is no need of constructors.This helps to write neat codes.

Eloquent ORM-This allows us to work with the database objects and relationships using an easily understandable syntax.

Inversion of control (IoC) principle-It is a Programming style where a framework controls the program flow.

Blade-Its a system for maintaining templates.

Command Line Interface (CLI)-Artisan is the CLI used in Laravel.It provides a number of helpful commands that can assist you while you build your application.

Installation and environment set up:

First set up the environment

$sudo apt-get update

$sudo apt-get upgrade

Install LAMP (Linux, Apache, MariaDB, PHP)  server.

$sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql php5-gd

I would recommend you to use PHP 5.4 or above because of the older versions installation of dependencies with composer takes much time.

$sudo apt-get install python-software-properties

$sudo add-apt-repository ppa:ondrej/php5-oldstable

$sudo apt-get update

$sudo apt-cache policy php5

Install the necessary PHP along with the needed extensions.

 $sudo add-apt-repository ppa:ondrej/php5

 $sudo apt-get update

 $sudo apt-get install php5 php5-mcrypt php5-gd

 $sudo php5enmod mcrypt

Install composer

$ curl -sS https://getcomposer.org/installer | php

Then we need to move composer to the bin directory and enable permissions to the folder.

$ sudo mv composer.phar /usr/local/bin/composer

$ sudo chmod +x /usr/local/bin/composer

Clone the master repo of laravel from github.

$cd /var/www

$git clone https://github.com/laravel/laravel.git

We get into the code directory and install all dependencies needed with the help of composer.

$ cd /var/www/laravel

$ sudo composer install

Then give proper permission to files with chmod command as used before.

Create a new directory  for your new Laravel project. After that, move to the path where you have created the new directory and type the following command there to install Laravel.

$composer create-project laravel/laravel –-prefer-dist

Start Laravel service by the following command:

$php artisan serve

You will see a URL. Open that URL in the browser. To ensure that Laravel has been installed successfully .

webpage

 

Application Structure :

The root directory of Laravel:

app − This directory contains the core code of the application.

bootstrap − It contains the application bootstrapping code.

config − It contains configuration files of the application.

database − This folder contains  database migration.

public − This is the  root file of the application. It contains the assets of the application like JavaScript, CSS, Images, etc.

resources − It contains raw assets ,localization and language files, and templates .

storage − It has app storage,framework storage , and application-generated logs.

test − This directory contains various test cases.

vendor − It  contains composer dependencies.

App directory contains the following subdirectories :

Console − All the artisan commands are stored here.

Events − This directory stores events that your application can raise.

Exceptions − It has the application’s exception handler.

Http − It contains your controllers and requests.

Jobs − This directory contains the queueable processes for your application.

Model view controller flow :

Laravel follows the model-view-controller (MVC) architectural pattern.A browser sends a request, which is received by a web server.This request is given to the Laravel routing engine.Based on the routing pattern Laravel router sends it to the controller. Sometimes, the controller will immediately render a view, which is a template that gets converted to HTML and sent back to the browser. More commonly for dynamic sites, the controller interacts with a model and communicates with the database. After invoking the model, the controller then renders the final view (HTML, CSS, and images) and returns the complete web page to the user’s browser.

laravel_mvc

Advantages of the framework:

Laravel is an elegant framework with many assets. It has clean code and APIs.The code is easily maintainable by the developer.It has a strong version control system and user-friendly interface.The customized tools in Laravel help in the development of application easier without any complications.With an integrated unit testing support system, we can ensure the proper working of the application.It provides high performance and security.Laravel framework stays up to date with the technology.Many versions with more features have been developed to extend the whole framework .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s