June 3, 2014

Laravel: From PHP apprentice to artisan

Written By Martin Sandhu
Scroll

Since the early days of PHP, with its uses just to develop personal home pages, it has grown into a vast network of frameworks mixed and blended together. As it grows from a highly dense syntax based language, it has now ever branching and rooting into several different frameworks, all of which are trying to empower the developer to rapidly construct, debug and craft beautiful applications.

As many organisations use several different frameworks to construct bespoke applications, the popularity of the specific PHP framework used increases. Examples of such frameworks are Yii, CodeIgniter and Cakephp, which have been described as being three of the top ten PHP frameworks of 2013 by stylish web designer. With many young developers wanting to construct their own applications and learn PHP, a PHP framework known only as Laravel arose by the end of 2013. In a survey conducted by site point of which PHP framework, developers where enthusiastic about, Laravel came out to be the number one preferred PHP framework.

Wondering why Laravel is taking PHP to new heights?… Well, as through the evolutions of Laravel (4.0), the developers have aimed to combine “the very best of what we have seen in other web frameworks”, which includes the likes of Ruby on Rail, ASP.Net MVC and Sinatra. The combination of such languages has resulted in Laravel having several advantages through…..

Eloquent ORM

As many beginner PHP developers would have started off by writing several SQL statements to perform PHP CRUD actions, Laravel’s Eloquent ORM defines each procedure into a single line, whilst further outlining constraints between database tables in the form of database objects. It even has a fluent query builder which is supported by Eloquet.

$task =Table::find(1);
$task->title = ‘test’;
$task->save();

Routing

Simple routing just got a whole lot easier…as an application becomes more complex with greater functionalities routes may need to be restricted or moved. Unlike other MVC frameworks Laravel can either make a controller responsible for what the users sees or allow the routing class to carry out the request itself.

Requesting the controller to handle a login
Route::get('users/{id}', 'Users@show');

Controllers (Services)

Laravel wants to ensure RESTfull services are slim and easy to write with minimal bugs. The mixture of an elegant Routing and Eloquent design, it provides a simple boilerplate giving the user more control of CRUD operations to handle POST and GET requests for different resource types and sizes.

class TestController extends Controller {
public function index() {}
public function create() {}
public function store() {}
public function show($id) {}
public function edit($id) {}
public function update($id) {}
}

Template Engine (view)

Another great advantage, is that Laravel has is its own template engine, known as Blade. This in turn has enables the developer to write more readable and reusable code for specific or shared views. Unlike other PHP frameworks, Blade enforces a policy of beautiful clean coding, whereas other frameworks tend to fail and fall into spaghetti html code.

@extends('layouts.master')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@stop
@section('content')
<p>This is my body content.</p>
@stop

From identifying the several properties which have brought Laravel to the spotlight, you can see the several similarities of “fruit punch” of frameworks and languages Laravel is based upon. Yet a small jump into Laravel can get you ticking, as it has met its aim of being a framework for web artisans, through its simplicities in design. On an end note, Laravel’s impact will be seen in the PHP developers’ community as its evolution will continue.