Reasons Why You Might Switch To Laravel PHP Framework

I realize that the market is asking for WordPress, Drupal, CodeIgniter, Zend, or CakePHP, but i am sure that you guys, will receive, at least one of these jobs where the client let’s you do your own thing (use your own framework, own web ui toolkit etc.). Today i’ll introduce you to some good and valid reasons why you might switch to this framework. I’ve been playing with it these weeks (both with the idea and the code examples, they are fun to try, and i encourage you to). I am not trying to market Laravel here (they didn’t pay me for it lol)

I’ll list some of the features that amazed me plus some general reasons why you might desire to switch to it. So here i go:

1 – Purely Awesome Routing

This one is so good that the documentation writers decided to put it in the first place. It is capable of returning:

  • Simple Strings
  • JSON and JSONP responses
  • XML Responses
  • Views
  • Multipart Form Data

Straight out of the box. It enables you to write a REST API very easily on top of the rest of your application. Suppose you have a route like this:

/products pointing to ProductsController@index

You can write another route:

/api/products

That fetches 10 products from the database and sends them in a JSON array to the client. You have the capability to send arrays as JSON responses via Response::json method. I believe every application should have an accessible API, so the users can create desktop, mobile, tablet applications much easier with it 😉

Routing also enables you to write different kinds of controller methods in different classes without having to have the class name look like the URI (in the case of CodeIgniter, where Products controller points to  /products ). You decide what HTTP request points to what controller and gives out what response.

2 – User Authentication Out of the Box

Another real cool thing with this framework is that, user authentication comes out of the box in here. It supports checking for an user’s authentication, manually authenticating users (say user has problems logging in, no problem, you authenticate him manually), and you can verify an user’s credentials without logging him in (this is true in another frameworks too if you separate the authentication / verification layers, just thought it would be worth to mention that laravel has this in a single line. Your preferences might clearly differ)

3 – Powerful ORM

I’ve had some damn fun with this one. They named their methods differently for database operations like:

skip(10)->take(5)

Instead of saying “OFFSET 10 LIMIT 5”, they are using human readable terms to move around in the database.

Another cool thing is that, after an insert, you can get the primary ID of an object, and work with that newly created data much easier, than say, with other frameworks. Especially in CodeIgniter, after an insert, i had to find out the latest data (Which was risky, because you could fetch different data that doesn’t belong to the user, and give him permission to modify it)

But the best and most important feature with this ORM implementation, it is that you don’t have to write your own database logic with your hand like in CodeIgniter. Where you might want to do a “create_example” function in your model, in Laravel you can simply do it by using the method chaining feature in PHP with a simple line like:

[pullquote]Example::insert(array(“title” => $title_data, “desc” => $desc_data”));[/pullquote]

 

The built-in IoC Container resolves it to  the correct model for you.  You don’t have to write CRUD’s anymore and you don’t have to make much verifications either because the ORM makes it possible to limit mass-assignment and implement database relations in an abstract and beautiful way.

 

 

4 – Powerful Templating System

But what i really liked about this PHP framework was that, it came with a neat templating system, called Blade, that helped me to write my views much faster. Instead of using the old:

[pullquote] or [/pullquote]

I could something much more pretty like this:

[pullquote]{{ echo $variable; }}[/pullquote]

It looks much prettier and readable. And using the default nesting system, you add as many as subviews in different hierarchies to your parent views.

Where in other frameworks, you have to save the parent view in a variable, and add up other views in it, in Laravel Framework you can use PHP’s method chaining features (from PHP 5.3 upwards) to nest your sub-views using the nest method from the View class.

5 – Beautiful Class Usage Conventions

Another thing i loved about Laravel, is that, instead of embedding the libraries and models in your controller class in CodeIgniter, you are able to call class Using the following notation:

[pullquote]Classname::method()[/pullquote]

Don’t be fooled by the double colons, it’s not a static method call, but rather a special system where using the double colon notation, will instantiate that object, and remove the reference at the end of usage, saving both memory and space, using things only when they are needed.

 6- Others

There are some features that i do not consider as important enough to use a whole category for them, but i will still mention them here:

  • Very nice unit testing (validity assertions, route tests via the call method etc)
  • The IoC Container (A proxy where you can instantiate objects only when needed)
  • Cool array and string functions (You can use dot notation for string hierarchies and array hierarchies)

Overall, i can say that, without trying to insult CodeIgniter users, that Laravel Framework is superior, and i see myself using it very long time.The richness of features, mixed with the cool features such as the IoC Container, and the ease of use (they have gone in their way to make database model methods to be human readable, and fun, figure).

I encourage you cute young new programmers, to try it out and have some fun nerd style.

Published
Categorized as News