Upgrade Guide

High Impact Changes

Medium Impact Changes

Upgrading To 8.0 From 7.x

Estimated Upgrade Time: 15 Minutes

{note} We attempt to document every possible breaking change. Since some of these breaking changes are in obscure parts of the framework only a portion of these changes may actually affect your application.

PHP 7.3.0 Required

Likelihood Of Impact: Medium

The new minimum PHP version is now 7.3.0.

Updating Dependencies

Update the following dependencies in your composer.json file:

  • guzzlehttp/guzzle to ^7.0.1
  • facade/ignition to ^2.3.6
  • laravel/framework to ^8.0
  • laravel/ui to ^3.0
  • nunomaduro/collision to ^5.0
  • phpunit/phpunit to ^9.0

The following first-party packages have new major releases to support Laravel 8. If applicable, you should read their individual upgrade guides before upgrading:

In addition, the Laravel installer has been updated to support composer create-project and Laravel Jetstream. Any installer older than 4.0 will cease to work after October 2020. You should upgrade your global installer to ^4.0 as soon as possible.

Finally, examine any other third-party packages consumed by your application and verify you are using the proper version for Laravel 8 support.

Collections

The isset Method

Likelihood Of Impact: Low

To be consistent with typical PHP behavior, the offsetExists method of Illuminate\Support\Collection has been updated to use isset instead of array_key_exists. This may present a change in behavior when dealing with collection items that have a value of null:

  1. $collection = collect([null]);
  2. // Laravel 7.x - true
  3. isset($collection[0]);
  4. // Laravel 8.x - false
  5. isset($collection[0]);

Database

Seeder & Factory Namespaces

Likelihood Of Impact: High

Seeders and factories are now namespaced. To accommodate for these changes, add the Database\Seeders namespace to your seeder classes. In addition, the previous database/seeds directory should be renamed to database/seeders:

  1. <?php
  2. namespace Database\Seeders;
  3. use App\Models\User;
  4. use Illuminate\Database\Seeder;
  5. class DatabaseSeeder extends Seeder
  6. {
  7. /**
  8. * Seed the application's database.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. ...
  15. }
  16. }

If you are choosing to use the laravel/legacy-factories package, no changes to your factory classes are required. However, if you are upgrading your factories, you should add the Database\Factories namespace to those classes.

Next, in your composer.json file, remove classmap block from the autoload section and add the new namespaced class directory mappings:

  1. "autoload": {
  2. "psr-4": {
  3. "App\\": "app/",
  4. "Database\\Factories\\": "database/factories/",
  5. "Database\\Seeders\\": "database/seeders/"
  6. }
  7. },

Eloquent

Model Factories

Likelihood Of Impact: High

Laravel’s model factories feature has been totally rewritten to support classes and is not compatible with Laravel 7.x style factories. However, to ease the upgrade process, a new laravel/legacy-factories package has been created to continue using your existing factories with Laravel 8.x. You may install this package via Composer:

  1. composer require laravel/legacy-factories

The Castable Interface

Likelihood Of Impact: Low

The castUsing method of the Castable interface has been updated to accept an array of arguments. If you are implementing this interface you should update your implementation accordingly:

  1. public static function castUsing(array $arguments);

Increment / Decrement Events

Likelihood Of Impact: Low

Proper “update” and “save” related model events will now be dispatched when executing the increment or decrement methods on Eloquent model instances.

Events

The Dispatcher Contract

Likelihood Of Impact: Low

The listen method of the Illuminate\Contracts\Events\Dispatcher contract has been updated to make the $listener property optional. This change was made to support automatic detection of handled event types via reflection. If you are manually implementing this interface, you should update your implementation accordingly:

  1. public function listen($events, $listener = null);

Framework

Maintenance Mode Updates

Likelihood Of Impact: Optional

The maintenance mode feature of Laravel has been improved in Laravel 8.x. Pre-rendering the maintenance mode template is now supported and eliminates the chances of end users encountering errors during maintenance mode. However, to support this, the following lines must be added to your public/index.php file. These lines should be placed directly under the existing LARAVEL_START constant definition:

  1. define('LARAVEL_START', microtime(true));
  2. if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
  3. require __DIR__.'/../storage/framework/maintenance.php';
  4. }

The php artisan down --message Option

Likelihood Of Impact: Medium

The --message option of the php artisan down command has been removed. As an alternative, consider pre-rendering your maintenance mode views with the message of your choice.

Manager $app Property

Likelihood Of Impact: Low

The previously deprecated $app property of the Illuminate\Support\Manager class has been removed. If you were relying on this property, you should use the $container property instead.

The elixir Helper

Likelihood Of Impact: Low

The previously deprecated elixir helper has been removed. Applications still using this method are encouraged to upgrade to Laravel Mix.

Mail

The sendNow Method

Likelihood Of Impact: Low

The previously deprecated sendNow method has been removed. Instead, please use the send method.

Pagination

Pagination Defaults

Likelihood Of Impact: High

The paginator now uses the Tailwind CSS framework for its default styling. In order to keep using Bootstrap, you should add the following method call to the boot method of your application’s AppServiceProvider:

  1. use Illuminate\Pagination\Paginator;
  2. Paginator::useBootstrap();

Queue

The retryAfter Method

Likelihood Of Impact: High

For consistency with other features of Laravel, the retryAfter method and retryAfter property of queued jobs, mailers, notifications, and listeners has been renamed to backoff. You should update the name of this method / property in the relevant classes in your application.

The timeoutAt Property

Likelihood Of Impact: High

The timeoutAt property of queued jobs, notifications, and listeners has been renamed to retryUntil. You should update the name of this property in the relevant classes in your application.

The allOnQueue() / allOnConnection() Methods

Likelihood Of Impact: High

For consistency with other dispatching methods, the allOnQueue() and allOnConnection() methods used with job chaining have been removed. You may use the onQueue() and onConnection() methods instead. These methods should be called before calling the dispatch method:

  1. ProcessPodcast::withChain([
  2. new OptimizePodcast,
  3. new ReleasePodcast
  4. ])->onConnection('redis')->onQueue('podcasts')->dispatch();

Failed Jobs Table Batch Support

Likelihood Of Impact: Optional

If you plan to use the job batching features of Laravel 8.x, your failed_jobs database table will need to be updated. First, a new uuid column should be added to your table:

  1. use Illuminate\Database\Schema\Blueprint;
  2. use Illuminate\Support\Facades\Schema;
  3. Schema::table('failed_jobs', function (Blueprint $table) {
  4. $table->string('uuid')->after('id')->nullable()->unique();
  5. });

Next, the failed.driver configuration option within your queue configuration file should be updated to database-uuids.

Routing

Automatic Controller Namespace Prefixing

Likelihood Of Impact: Optional

In previous releases of Laravel, the RouteServiceProvider class contained a $namespace property with a value of App\Http\Controllers. This value of this property was used to automatically prefix controller route declarations and controller route URL generation such as when calling the action helper.

In Laravel 8, this property is set to null by default. This allows your controller route declarations to use the standard PHP callable syntax, which provides better support for jumping to the controller class in many IDEs:

  1. use App\Http\Controllers\UserController;
  2. // Using PHP callable syntax...
  3. Route::get('/users', [UserController::class, 'index']);
  4. // Using string syntax...
  5. Route::get('/users', 'App\Http\Controllers\[email protected]');

In most cases this won’t impact applications that are being upgraded because your RouteServiceProvider will still contain the $namespace property with its previous value. However, if you upgrade your application by creating a brand new Laravel project, you may encounter this as a breaking change.

If you would like to continue using the original auto-prefixed controller routing, you can simply set the value of the $namespace property within your RouteServiceProvider and update the route registrations within the boot method to use the $namespace property:

  1. class RouteServiceProvider extends ServiceProvider
  2. {
  3. /**
  4. * This namespace is applied to your controller routes.
  5. *
  6. * In addition, it is set as the URL generator's root namespace.
  7. *
  8. * @var string
  9. */
  10. protected $namespace = 'App\Http\Controllers';
  11. /**
  12. * Define your route model bindings, pattern filters, etc.
  13. *
  14. * @return void
  15. */
  16. public function boot()
  17. {
  18. $this->configureRateLimiting();
  19. $this->routes(function () {
  20. Route::middleware('web')
  21. ->namespace($this->namespace)
  22. ->group(base_path('routes/web.php'));
  23. Route::prefix('api')
  24. ->middleware('api')
  25. ->namespace($this->namespace)
  26. ->group(base_path('routes/api.php'));
  27. });
  28. }

Scheduling

The cron-expression Library

Likelihood Of Impact: Low

Laravel’s dependency on dragonmantank/cron-expression has been updated from 2.x to 3.x. This should not cause any breaking change in your application unless you are interacting with the cron-expression library directly. If you are interacting with this library directly, please review its change log.

Session

The Session Contract

Likelihood Of Impact: Low

The Illuminate\Contracts\Session\Session contract has received a new pull method. If you are implementing this contract manually, you should update your implementation accordingly:

  1. /**
  2. * Get the value of a given key and then forget it.
  3. *
  4. * @param string $key
  5. * @param mixed $default
  6. * @return mixed
  7. */
  8. public function pull($key, $default = null);

Testing

The assertExactJson Method

Likelihood Of Impact: Medium

The assertExactJson method now requires numeric keys of compared arrays to match and be in the same order. If you would like to compare JSON against an array without requiring numerically keyed arrays to have the same order, you may use the assertSimilarJson method instead.

Validation

Database Rule Connections

Likelihood Of Impact: Low

The unique and exists rules will now respect the specified connection name (accessed via the model’s getConnectionName method) of Eloquent models when performing queries.

Miscellaneous

We also encourage you to view the changes in the laravel/laravel GitHub repository. While many of these changes are not required, you may wish to keep these files in sync with your application. Some of these changes will be covered in this upgrade guide, but others, such as changes to configuration files or comments, will not be. You can easily view the changes with the GitHub comparison tool and choose which updates are important to you.