Deferred Service Provider Compatibility with Laravel 5.7 or below

Published in Laravel on Feb 28, 2020

Illuminate\Contracts\Support\DeferrableProvider which was introduced in Laravel 5.8, so what happen if you need to make your package compatible with Laravel 5.7 or below while supporting the latest version.

You can skip implementing Illuminate\Contracts\Support\DeferrableProvider and instead add isDeferred() method to your Service Provider class, such as below:

<?php

namespace Acme;

use Illuminate\Support\ServiceProvider;

class ExampleServiceProvider extends ServiceProvider
{
    // ...

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [ /* ... */ ];
    }

    /**
     * Determine if the provider is deferred.
     *
     * @return bool
     */
    public function isDeferred()
    {
        return true;
    }
}