What’s new in Laravel 5
Laravel 5 was released this January amidst much anticipation. The new framework for PHP developers brings along some unique features and also some modifications to the previous architectural foundations. Laravel is both trying to make it simpler and make it more challenging for developers to think creatively and develop better applications. Here are some good things you should know about the latest update.
Directory Structure
A major change has been made to the latest Laravel’s folder structure. It comes with the PSR-4 auto loading standard, meaning that all classes are automatically namespaced. Default namespace for any web application remains “app” but can be changed using the syntax “php artisan app:name <your-app-name>.
Models remain in the app namespace and will be included in the app folder. Any application’s views, assets, and language files will be located in resource folder while the bootstrap, public and vendor directory retain their previous locations. Further, storage, test, database and config directories are now placed in the root folder of projects.
Peeking into the app folder now, developers would notice several classes which are explained later.
Laravel 5 also comes with an improved environment detection. As opposed to the complex and nested configuration directories we found in previous versions, Laravel 5 comes with a new .env file at the root taking care of all environment variables. Further, the php artisan tinker now uses the Psysh package against Boris.
Method injection
Up until the 4.2 version, developers would had to request IoC container to achieve class distance. However, it can be done simpler now by just declaring the class instance into the signature of controller method. The IoC takes care of the rest, even with other parameters playing a role.
<?php
// your class at "app/Classes/your_class.php"
namespace App\Classes
class YourClass
{
// your class implementation
}
// somewhere in one of your controller actions
public function myAction(\App\Classes\YourClass $MyObject)
{
// use $MyObject just like any other object
}
?>
Contracts
Acting as interface classes, contracts are the same tried and tested process of removing class dependencies and creating loosely coupled software elements. If an application process requires catching, one can use Illuminate\Contracts\Cache instead of concrete cache class. This also allows you to plug in and plug out the cache implementation without major changes to the package code.
Route catching
Route catching with the new Laravel helps speed up the route registration of applications and has clear performance benefits. It might however require a larger number of routes to be able to monitor the change in caching. Using the syntax “php artisan route:cache” and “php artisan route:clear”, developers can turn the caching on and off.
Route Middleware
Route Middle ware in Laravel 5 adds extra layers to HTTP routes. It would be a good tool to use when you require codes to be executed before each route or specific routes.
Authentication
With Laravel 5, you will not have to spend a lot of time writing the authentication broilerplate. Laravel’s 5 Registrar service supports this ready to use authentication.
Let us know if any other feature in Laravel 5 has caught your attention.