📜 ⬆️ ⬇️

Your next web application framework

Every time when there is a task of choosing a framework for writing a new project, we (web developers) most likely choose what we already know well and constantly use. The world of PHP frameworks is quite rich and the largest players are: CodeIgniter , Kohana , Symfony , Yii , Zend Framework . But I want to draw your attention to a fundamentally new, or rather a fundamentally new branch of the best framework with which I had occasion to deal. Meet Laravel 4!


What is a framework


First, let's find out what the framework really is. According to Wikipedia, the framework is:

The structure of the software system; software that facilitates the development and integration of various components of a large software project. The word “framework” is also used, and some authors use it as the main one, including not based on the English-language analogue at all.
')
The framework differs from the library concept in that the library can be used in a software product simply as a set of routines of similar functionality, without affecting the architecture of the software product and without imposing any restrictions on it. While the framework dictates the rules for constructing the architecture of the application, setting the default behavior at the initial stage of development, the framework that will need to be expanded and modified according to the specified requirements.


What is Laravel


Laravel is a set of best practices from the world of PHP development. From the framework it blows at the same time both simplicity and professionalism which its developers possess.

Simplicity begins during the installation phase. After all, it is enough to drive just one line in the command line and wait until everything is established:

composer create-project laravel/laravel project_name --prefer-dist 


And professionalism lies in the fact that the framework bears in itself and preaches the use of such patterns as:



And Laravel gives you the ability to use them extremely effectively. For example, to implement a DI of a class, it suffices to write:

 class UserController extends Controller { private $users; public function __construct(UserRepository $users) { $this->users = $users; } } 


Laravel will create an instance of the `UserRepository` class. And if the `UserRepository` also requires DI of some classes, Laravel will also create instances of them. (note. What is good and useful about DI and what other ways are there to implement it in this post?).

It is also worth mentioning that Laravel is easily expandable, that is, if you use a queue server and Laravel does not know how to work with it, then you just need to write a class (driver) to work with your queue server - inheriting from the Queue class and implementing the interface QueueInterface , and then register in the appropriate config that such a class should be used for the queues.

One of the main advantages of Laravel is the brevity and readability of its code. For example, to queue a task is enough to write:

 Queue::push('SendEmail@send', array('message' => $message)); 

or to trigger an event:

 Event::fire('user.login', array($user)); 


Brief, concise and elegant, is not it?

It is also worth mentioning the ORM in Laravel (what kind of framework if there is no ORM in it?), Which is called Eloquent (comment which means - eloquent, expressive). And he really lives up to his name. To select the first entry from the `users` table, for which we have the` User` model, we need to write:

 User::first(); 

or to search by users who are active and sort them by registration date, just write the following:

 $users = User::where('is_active', 1)->orderBy('created_at', 'DESC')->get(); 

The code is read very easy and pleasant.

Suppose we have a `roles` table and a table that links user roles and roles themselves -` user_roles`. To add a link in the `User` class, you just need to write 3 lines:

 public function roles() { return $this->belongsToMany(Role::class, 'user_roles'); } 


and if you want to select users along with their roles, the code will look like this:

 $users = User::with('roles')->get(); 

And the wow effect works again :)

In order to familiarize yourself with all the features and pleasures of the Eloquent ORM, I recommend looking into the official documentation and discovering a bunch of interesting possibilities (http://laravel.com/docs/eloquent).

Laravel is incredibly convenient and cool to create a RESTful API, because in the controller method you just need to write:

  $user = User::find(1); return $user; 

and Laravel transforms this model into JSON. Very comfortably. There are also other options for creating a RESTful API that should be explored in the official documentation.

I will not fully describe all the possibilities that Laravel gives a web developer, because it is impossible to take them all and write them in one post. Every day, when I come across Laravel development, I discover new ways to write this or that functionality.

Documented


Not a single framework has been so briefly and clearly documented as Laravel. Need to know how to work with queues? Please go to the Queues section and read how to work with them. It turns out that there are several options for working with them: choose the one you like or suit your task and go ahead! Want to learn how to expand the core? Please, and there are answers with examples.

Everything has already been taken care of


Above, I wrote how easy it is to use the capabilities of the framework. And this is not only a great ORM, convenient data return, but also incredibly beautiful and flexible routing, testability of everything and everything, Blade template maker, Schema Builder, etc. Speaking of tests, you no longer have to worry that when you use Mock objects in your tests, the framework may work in unexpected ways or not as you planned. Laravel already contains tests for all its functionality. You do not need to test the framework. Test your code. The developers reacted with great responsibility to the tests and performance of the framework.
You should not be surprised anymore that magic happens somewhere and something does not function as it should be. Everything here works exactly as written in the documentation.

Who is backstage?


Taylor otwell

image

The main developer framework. It is he who thinks about how the framework and its API should look, and decides whether or not to introduce this or that functionality.

Phill sparks

image

Dayle rees

image

Shawn mccool

image

All these guys have full access to the repository and are directly involved in the kernel.

?>


In conclusion, I want to say that Laravel is gaining momentum very quickly. In trending on github for a long time is in the first place, and among the PHP-frameworks on the 2nd. Communities appear, and they are quite responsive. There is also a community in Russia. We are few, but we are in vests :) Join us , we will be very happy.
Laravel returns those feelings when you first sat down for programming and you start to get those feelings that gave you the pleasure of programming in PHP, and did not turn the development into some kind of routine work.

Source: https://habr.com/ru/post/202638/


All Articles