Laravel 5.7 – Check Laravel 5.7 Stunning Features

by jay patel




Laravel is a new free open-source PHP web framework that made its arrival about 7 years ago in June 2011. Since then it has become one of the most popular PHP frameworks for developing web applications. As such, it is based on the MVC (Model View Controller) architectural pattern and Symfony. The first version Laravel 1.0 was released in June 2011 and the 5.6 version came in February this year. And now, the latest variant 5.7 is also on the roll in August 2018. The framework is said to get the bug fixes by February next year and implement the security-based fixes by August 2019.

This release continues to improvements for the previous version 5.6, and also includes some exciting new features.

In this blog post, I'm listing some cool features that are already announced by the Laravel team and taking some reference from the github repository.

Installation of Laravel 5.7 & New Features

What’s New in Laravel 5.7

 Summarizing Up

 

Laravel Nova

 

laravel nova

 

The most awaited laravel package that was announced by Taylor during Laracon US 2018, and which is a beautiful admin panel package for Laravel application. It is a code-driven admin panel for your new or existing laravel project. The previous version of Laravel still supports Nova, as it is a simple composer package. To know in depth about it follow the official documentation, also go through the introduction article on the medium by Taylor.

Laravel Nova is officially released now on Aug 22, 2018, the initial release v1.0.* (Orion) is now available to purchase from the official website.

 

Laravel Dump Server

Laravel Dump Server comes in a default package in Laravel 5.7. It is the development dependency in Laravel composer file. Instead of dumping data to the browser itself, it allows you to dump that data to the console or inside an HTML file.

 

laravel dump server

 

The above command executes a server in the background. It displays data through the console which is sent from the application. While Dump() works in the default scenario, when this command is not running in the background. You can get further information about Dump in its github directory.

 

 

php artisan dump-server

// Output to the HTML file.

php artisan dump-server -- format= html > report . html

 

 

This package is open sourced by the author, contribute if you have any idea for it.

 

Resources Directory Changes

Once you open the Laravel 5.7 application on your desired Code editor or IDE. You will see the directory structure changes in it. The Resource directory is made flattened and does not have any assets folder.

 

laravel development company

 

Taylor Otwell publicly said about this change in one of his tweet. As assets will no longer be in the Resource directory. Instead will contain JS, Sass, lang and views inside it.

 

laravel 5.7 resources directory

 

Email Verification

Laravel 5.7 also introduces new optional email verification feature. You can use this feature by adding email_verified_at timestamp column in the user’s migration table. Which comes default within the framework.

While to give newly joined users the functionality to verify their email. Implement the Must Verify Email interface in the User model.

 

 

namespace App;

use Illuminate \ Notifications\Notifiable;

use Illuminate \Contracts\Auth\MustVerifyEmail;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail

{

// ...

}

 

 

All the newly registered users receives an email address. Which contains an account activation link, once you implements the MustVerifyEmail interface. It activates their respective accounts as soon as they clicks on it.

Laravel 5.7 also provides a Middleware along with this email verification feature. Which works only with verified emails and not with unverified ones. As a result, this brings great feature to developers to ease their backend tasks.

 

 

'verified'  =>  \Illuminate\Auth\Middleware\EnsureEmailIsVerified  ::  class ,

 

 

To protect your routes only for verified emails, attach the middleware in the routes.

 

 

Route::get('profile/index', function () {

//

})->middleware('verified');

 

 

Guest User Gates / Policies

The previous Laravel version has the functionality to return false, if it founds any unauthenticated user trying to access the application. But in new Laravel 5.7, you can declare an optional type hint or could input a null default value to allow guest users pass through the authentication checks.

 

 

Gate::define' update-product'function   ?User   $user , Product   $product )  {

// ...

});

 

 

URL Generator & Callable Action

URL

Laravel 5.7 introduces a new callable syntax for action URLs. Which is same like the one in Laravel 5.6 that accepts string in action method. The main purpose of this new syntax is to directly enable you access the controller.

 

Basic syntax for callable syntax:

Previously,

 

$url  =  action' BlogController@index ' ) ;

$url  =  action' BlogController@view ' ) ,  [ 'id'  =>1] );

 

 

Now,

 

use  App\ Http Controllers\HomeController;

$url  =  action( [ BlogController :: class,   'index' ] ); 

$url  =  action( [ BlogController :: class,   'view'] ),  [ 'id'  =>  1] );

 

 

The new callable array syntax gives you the ease to access controller files from any text editor. Like VSCode, Sublime, Atom or any other editor that supports code navigation.

 

Paginator Links

This new feature helps controlling additional links that are displayed on either side of the paginator URL window. Working on pagination before, you would have seen three links in it which is by default. But in Laravel 5.7 you can define them explicitly, giving you more ease to handle pagination precisely.

 

 

{{   $pages->onEachSide(5)->links()  }}

 

 

Notification Localization

With the release of this few feature in Laravel 5.7, you will now get the permission to send the notifications in a locale apart from the current languages. In fact, the framework will be familiar with this locale even if the notification is lined up. Even the Illuminate\Notifications\Notification class provides a locale method to get the desired language. When you are formatting the notification, the application gets converted into locale and once this formatting process is complete, it goes back into the previous locale.

 

 

$user ->notify( (new  NewUser ($user) ) ->locale'np' ) );

 

 

You could also utilize the facade to set localization for multiple notification entries.

 

 

Notification::locale'np' )

-> send $subscribers new  WeeklyNewsletter $newsletter ) );

 

 

Improved Error Messages

Laravel 5.7 also gives you the functionality to easily track your error messages. As in Laravel 5.7, you can get short messages explaining the non existence of method or any other attribute. Instead of just pointing out the underlying object with confusing red lines.

better error laravel 5.7

Testing Artisan Commands

The first employee of Laravel (Mohamed Said) recently contributed a great feature in the framework to test artisan commands. He announced via his tweet about this feature, and which is also documented in official documentation already. Now, with this addition, framework now provides a simple API for testing console applications that ask for user input.

 

 

classInstallCommandTest extends TestCase

{

publicfunctiontestInstallTest()

{

$this->artisan('app:setup',[

'name'=>'Setup New Project'

])

->expectsQuestion('Are you sure you want to start installation ?','Yes')

->expectsOutput('Initializing...')

->expectsQuestion('Please select your preferred version','v2.5')

->expectsOutput('Installing...')

->expectsQuestion('Do you want to run composer dump -o ?','Yes')

->expectsOutput('Generating Optimized Autoload Files...')

->assertExitCode(0);

}

}

 

Wrap Up

We can see that Laravel in its new version 5.7 has introduced some of the important changes from the previous variants and also brought forward some new features as well. This will certainly make the task of web application much easier.

Laravel 5.7 is pretty advanced in comparison to its previous version. It introduces diverse functionalities which makes it on top of the PHP frameworks charts. While the enhanced features of Laravel 5.7 also includes bug fixes, security fixes and others.

So if you still have any questions regarding the new Laravel version, feel free to ask them in the comments section below.



Leave a Reply

Your email address will not be published. Required fields are marked *

   Confirm you are not a spammer
   Notify me of follow-up comments by email.
avtar
Piyaa Sharma
Great list you’ve curated here. Laravel 5.7 makes it easier to track down error messages caused by dynamic calls to Eloquent models. Dump Server will be the development dependency in laravel/laravel composer file. Thanks for sharing!