📜 ⬆️ ⬇️

Laravel 4. Differences and comparisons

image

Relatively recently, the first Beta of the Laravel framework was released. Comrade rsvasilyev began publishing articles on development in the 4th version, I, in turn, want to describe the new advantages and compare it with its previous version.

If you are interested in this, please under cat.

')
There have been a lot of changes, but perhaps I will start with my favorite change, which has eliminated bicycles.
Previously, we could use only 2 static-regular expressions for URLs of the form / user / {value} .

The first is a sequence of numbers:

Route::get('user/(:num)', function ($id) { return $id; }); 


Second - Alphanumeric:

 Route::get('user/(:any)', function ($name) { return $name; }); 


In the new version, the situation has changed and now we ourselves can assign a regular expression to each value.
This is done quite simply, with one finger movement:

 Route::get('news/{habr}', function($habr) { return $habr; }) ->where('habr', '[A-Za-z]+'); 


or

 Route::get('news/fullnews/{idNews}', function($idNews) { return $idNews; }) ->where('idNews', '[0-9]+'); 

It is also worth clarifying some peculiarity: If you replace {idNews} with {idNews?} And add the function value to the parameter ($ idNews = '4') , then by contacting / news / fullnews , we get the news with ID = 4 .


Easy, isn't it? Let's go further.

Added the ability to use not only the group for filters, but also to specific URLs:

 Route::filter('blacklist', function() { return ', Habrahabr.'; }); Route::when('chat/*', 'blacklist'); 

Thus, to all URLs of the form: chat / * , the blacklist filter will be applied.


Everything described above was used by me personally in the project, I will describe the rest below.

Routes



New features



Link to the Framework itself and to the documentation for the 4th version . (There is no translation yet)

If you have read my first article to the end, then I will experience a bit of pleasure.

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


All Articles