Laravel 5.7 is live – here’s what’s new

  • 2018-11-30 03:12 AM
  • 157

Laravel 5.7 was released almost a month after Laracon US 2018. This version continues with improvements made in Laravel 5.6, introducing Laravel Nova, email verification alongside other cool new features we will be discussing in this article. In this article, we will talk about some cool features of Laravel 5.7.

Aiodex’s Referral Program will give you 20% -80% commission from their transaction fee for 7 years. The value will be calculated starting from the date the member you invite sign up. Starting from the first year is 20%, after each year increased to 10% from the first day of next year. For the 300K members who are enjoying the transaction fee refund policy, if they are one of your invited members, you will receive a commission until the system start charging their transaction fees. For example, if the new system start charging from 2020–01–01, you will start receiving commissions and since it is the second year then you will receive 30% ☞ https://aiodex.com/p/referral-program
Get Free 15 Geek ☞ https://my.geekcash.io/ref/5b3c4924d38b6158ce04633f or http://geekcash.org/
Learn to Code ☞ https://codequs.com
CodeGeek’s Discuss ☞ https://discord.gg/KAe3AnN
Playlists Video Tutorial ☞ http://bit.ly/2IQdTwR

Laravel Nova

Nova is a beautifully designed admin dashboard panel for Laravel.

As Taylor Otwell Says :

We’ve sweat the small details and carefully crafted Nova to not only look great, but to be a joy to work with.

Laravel Nova

Laravel Nova, which is a Composer installed package can be seen as a standalone service. It makes it possible to build an admin dashboard panel. Is Nova a CMS? Well, it is not. I mean it should be a CMS if all the packages bootstrapped with Nova came out of the box in most content management systems, it would pass for one.

Purchasing a license for this awesome package comes at a whopping $90/site for a solo and $199/site for an enterprise plan. Laravel Nova has a few required packages before installation:

  • Composer
  • Node and Npm
  • Laravel Framework 5.6+
  • Laravel Mix

When the following requirements are met, you may download a Nova release from the release section on the Nova website after purchasing a license.

Email verification

In recent times, there has been a desperate need to validate user emails. In these times, we have painlessly implemented this logic on each and every application that requires email verification. Laravel 5.7 comes with email verification that is configured out of the box to verify email addresses.

This can be implemented in Laravel 5.7 by using the Illuminate\Auth\MustVerifyEmail trait on an App\User model which implements the Illuminate\Contracts\Auth\MustVerifyEmail contract like so:

    <?php

    namespace App;

    use Illuminate\Auth\MustVerifyEmail;
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;

    class User extends Authenticatable implements MustVerifyEmailContract
    {
        use MustVerifyEmail, Notifiable;

        // ...
    }

A table that uses email verification must have an email_verified_at column. These columns are already defined in the User table migration file. Adding this column is as painless as running php artisan migrate .

The Auth\VerificationController comes with all the necessary logic needed to verify emails out of the box. To call this controller on routes, all we need to do is to pass the verify parameter to the Auth:routes method like so:

    Auth::routes(['verify' => true]);

Laravel 5.7 comes shipped with a verified method, which can be added to specific routes. To achieve this, a middleware can be configured to only allow a given route(s) to the users. This way, such routes become accessible to users who have verified emails.

    Route::get('profile', function () {
        // Only verified users may enter...
    })->middleware('verified');

Testing with Artisan

Laravel now makes it possible to test console applications, which accept inputs. Testing console applications comes off as easy as using three methods, expectQuestion, expectsOutput, and assertExitCode. An example of a simple console application test case is shown below:

    Artisan::command('question', function () {
        $name = $this->ask('What is your name?');

        $coding_style = $this->choice('Tabs or Spaces?', [
            'Tabs',
            'Spaces'
        ]);

        $this->line('Your name is '.$name.' and you prefer '.$coding_style.'.');
    });

You may test this console application utilizing the three methods mentioned above like so:

    /**
     * Test a console command.
     *
     * @return void
     */
    public function test_console_command()
    {
        $this->artisan('code:style')
             ->expectsQuestion('What is your name?', 'John Doe')
             ->expectsQuestion('Tabs or Spaces?', 'Tabs')
             ->expectsOutput('Your name is John Doe and you prefer Tabs.')
             ->assertExitCode(0);
    }

Pagination link customization

Thanks to Michal Putkowski for his contribution, Laravel now has a new method, appended to the paginate method. This method linksOnEachSide eliminates the need for a custom pagination view in most cases.

    <?php

    User::paginate(10)->linksOnEachSide(5);

This means five pagination links will appear on each side of the paginator.

Tweet about pagination

To check out how this was implemented, you can view the PR here.

Symfony dump server

At this years Laracon, Taylor Otwell announced that Symfony dump server will be shipped in Laravel 5.7. Symfony dump server when running redirects all reference to the dump method in a console window. This allows developers to debug and inspect views without contorting HTTP response outputs. To start up the dump server type php artisan dump-server in your Laravel project directory.

Symfony dump server CLI output

Feeling like contributing at the upcoming Hacktoberfest? Symfony dump-server wouldn’t be a bad start.

Callable action URLs

The action method binds a controller to a URL. An action is callable because actions can be referenced in an array syntax. As of Laravel 5.6 action URLs were were defined thus:

    $url = action('[email protected]');

Callable action URLs were introduced in Laravel, thanks to Sebastian De Deyne. We can reference actions in callable array syntax like so:

    use App\Http\Controllers\FooController;

    $url = action([FooController::class, 'bar'])  

PS: Callable action URLs will come in handy when navigating around your code base if of course, your IDE supports it.

Flattened resources directory

Flattened resource file tweet

Yes! Laravel 5.7 comes with a missing parent directory, the assets. In Laravel 5.6, the folder structure was like so:

      resources
      ├── assets
      │   ├── js
      │   └── sass
      ├── lang
      │   └── en
      └── views

In this current version of Laravel (5.7), the resources/assets have been flattened into resources. The folder structure now looks like this:

      resources
      ├── js
      ├── lang
      ├── sass
      └── views  

We no longer need to navigate into the assets directory every time we want to use our js or sass assets. With this new update, we can call our assets directly from the resources folder.

Isn’t that awesome!

Notification localization

Laravel now allows you to send notifications in a new language other than the current or default language, it will also remember this locale if it is queued. This can be implemented by adding the locale method which is now offered in the Illuminate\Notifications\Notification class.

    $user->notify((new emailVerified($user_id))->locale('es'));

This could be used to send a notification to the user in his local language, leveraging on his/her country entered during registration. This locale defaults to its original state after the notification has been sent.

File system read/write streams

Laravel filesystems integration now offers readStream and writeStream methods, which can be implemented like so:

    Storage::disk('rackspace')->writeStream(
        'remote-file.zip',
        Storage::disk('local')->readStream('local-file.zip')
    );

If you are implementing this Illuminate\Contracts\Filesystem\Filesystem contract, you should add the readStream and writeStream methods.

Improved error messages for dynamic calls to Eloquent models

Laravel now sends problem specific error messages.

Improved error messages tweet

Concise error messages will come in handy when debugging Laravel applications. Here’s a link to the pull request submitted by Joseph Silber, if you’re curious on how this was implemented behind the scenes.

Error page redesign

Laravel 5.7 comes with beautifully redesigned error pages for handling HTTP exceptions packed with some sense of humor. Our major focus in this article is the 404 , 403 and 500 error codes.
404

New 404 page

403

New 403 page

500

New 500 page

Conclusion

In this article, we have looked at the new features of Laravel 5.7. You can view the release notes and the upgrade guide, to know how to upgrade your current Laravel application to version 5.7.

Suggest