What’s New In Laravel 5.8 – New Features Must Try

1. Automatic policy resolution

namespace App\Providers;
use App\Post;
use App\Policies\TransactionPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
 * The policy mappings for the application.
 * @var array
 protected $policies = [
 Transaction::class => TransactionPolicy::class,
 * Register any application authentication / authorization services.
 * @return void
 public function boot()

Now you can register policies using Gate::guessPolicyNamesUsing   this method will call from  AuthServiceProvider  class

use Illuminate\Support\Facades\Gate;
Gate::guessPolicyNamesUsing(function ($modelClass) {
    // return policy class name...

2. Carbon 2.0 Support

Laravel 5.8 provides the new features which are coming in Carbon 2.0 library to extend the functionalities by users.

3. Eloquent hasOneThrough Relationship

Now it is easy to track down has to Multilevel Models. For example, if a user has one Account and Account has one Account history it will now easily track down by using hasOneThrough method.

//Get the account history for the user.
public function accountHistory()
    return $this->hasOneThrough(AccountHistory::class, Account::class);

4. PSR-16 Cache Compliances

In order to allow a more granular expiration time PSR-16 caching standard, cache time to live has been changed from minutes to seconds. Now you should pass the no of seconds as below

// Laravel 5.7 - Store item for 40 minutes...
Cache::put('key', 'val', 40);

// Laravel 5.8 - Store item for 30 seconds...
Cache::put('key', 'val', 30);

// For Both Laravel 5.7 & 5.8 - Store item for 80 seconds...
Cache::put('key', 'val', now()->addSeconds(80));

5. Multiple Authentication Guards

In Laravel 5.8, you may assign multiple guards that should authenticate the incoming request:

Broadcast::channel('channel', function() {
    // ...
}, ['guards' => ['web', 'admin','users']])

6. Token Guard Token Hashing

In laravel 5.8 now supports storing API tokens as SHA-256 hashes providing the security over storing plain-text tokens.

7. Eloquent Resource Key Preservation

use App\User;
use App\Http\Resources\User as UserResource;

Route::get('/user', function () {
    return UserResource::collection(User::all());

8. Artisan Serve Improvements

In Laravel 5.8 support for multiple up to 8009 port as previous only support only on 8000.

9. Email Validation Improved

Validation improved by  egulias/email-validator  which provide invalid email ids having  illegal characters.

10. Default Scheduler Timezone

Now you can customize laravel timezone of a scheduled task using the timezone method:


You may define scheduleTimezone method in your app/Console/Kernel.php

protected function scheduleTimezone()
    return 'America/Chicago';

11. Php Artisan Improvements

In previous releases of Laravel, the command’s options are passed via an array as the second argument to the method:

PREVIOUS (before laravel 5.8)

use Illuminate\Support\Facades\Artisan;

Artisan::call('migrate:install', ['database' => 'test']);

In Laravel 5.8

Artisan::call('migrate:install --database=test');

You may also like...

Leave a Reply

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