Upgrade Guide

High Impact Changes

Medium Impact Changes

Upgrading To 8.0 From 7.x

Estimated Upgrade Time: 15 Minutes

exclamation

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 
3// Laravel 7.x - true
4isset($collection[0]);
5 
6// Laravel 8.x - false
7isset($collection[0]);
1$collection = collect([null]);
2 
3// Laravel 7.x - true
4isset($collection[0]);
5 
6// Laravel 8.x - false
7isset($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 
3namespace Database\Seeders;
4 
5use App\Models\User;
6use Illuminate\Database\Seeder;
7 
8class DatabaseSeeder extends Seeder
9{
10 /**
11 * Seed the application's database.
12 *
13 * @return void
14 */
15 public function run()
16 {
17 ...
18 }
19}
1<?php
2 
3namespace Database\Seeders;
4 
5use App\Models\User;
6use Illuminate\Database\Seeder;
7 
8class DatabaseSeeder extends Seeder
9{
10 /**
11 * Seed the application's database.
12 *
13 * @return void
14 */
15 public function run()
16 {
17 ...
18 }
19}

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},
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:

1composer require laravel/legacy-factories
1composer 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:

1public static function castUsing(array $arguments);
1public 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 EventServiceProvider Class

Likelihood Of Impact: Low

If your App\Providers\EventServiceProvider class contains a register function, you should ensure that you call parent::register at the beginning of this method. Otherwise, your application's events will not be registered.

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:

1public function listen($events, $listener = null);
1public 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:

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

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.

The php artisan serve --no-reload Option

Likelihood Of Impact: Low

A --no-reload option has been added to the php artisan serve command. This will instruct the built-in server to not reload the server when environment file changes are detected. This option is primarily helpful when running Laravel Dusk tests in a CI environment.

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:

1use Illuminate\Pagination\Paginator;
2 
3Paginator::useBootstrap();
1use Illuminate\Pagination\Paginator;
2 
3Paginator::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 have 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:

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

Note that this change only affects code using the withChain method. The allOnQueue() and allOnConnection() are still available when using the global dispatch() helper.

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:

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

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

In addition, you may wish to generate UUIDs for your existing failed jobs:

1DB::table('failed_jobs')->whereNull('uuid')->cursor()->each(function ($job) {
2 DB::table('failed_jobs')
3 ->where('id', $job->id)
4 ->update(['uuid' => (string) Illuminate\Support\Str::uuid()]);
5});
1DB::table('failed_jobs')->whereNull('uuid')->cursor()->each(function ($job) {
2 DB::table('failed_jobs')
3 ->where('id', $job->id)
4 ->update(['uuid' => (string) Illuminate\Support\Str::uuid()]);
5});

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. The 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:

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

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:

1class RouteServiceProvider extends ServiceProvider
2{
3 /**
4 * The path to the "home" route for your application.
5 *
6 * This is used by Laravel authentication to redirect users after login.
7 *
8 * @var string
9 */
10 public const HOME = '/home';
11 
12 /**
13 * If specified, this namespace is automatically applied to your controller routes.
14 *
15 * In addition, it is set as the URL generator's root namespace.
16 *
17 * @var string
18 */
19 protected $namespace = 'App\Http\Controllers';
20 
21 /**
22 * Define your route model bindings, pattern filters, etc.
23 *
24 * @return void
25 */
26 public function boot()
27 {
28 $this->configureRateLimiting();
29 
30 $this->routes(function () {
31 Route::middleware('web')
32 ->namespace($this->namespace)
33 ->group(base_path('routes/web.php'));
34 
35 Route::prefix('api')
36 ->middleware('api')
37 ->namespace($this->namespace)
38 ->group(base_path('routes/api.php'));
39 });
40 }
41 
42 /**
43 * Configure the rate limiters for the application.
44 *
45 * @return void
46 */
47 protected function configureRateLimiting()
48 {
49 RateLimiter::for('api', function (Request $request) {
50 return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
51 });
52 }
53}
1class RouteServiceProvider extends ServiceProvider
2{
3 /**
4 * The path to the "home" route for your application.
5 *
6 * This is used by Laravel authentication to redirect users after login.
7 *
8 * @var string
9 */
10 public const HOME = '/home';
11 
12 /**
13 * If specified, this namespace is automatically applied to your controller routes.
14 *
15 * In addition, it is set as the URL generator's root namespace.
16 *
17 * @var string
18 */
19 protected $namespace = 'App\Http\Controllers';
20 
21 /**
22 * Define your route model bindings, pattern filters, etc.
23 *
24 * @return void
25 */
26 public function boot()
27 {
28 $this->configureRateLimiting();
29 
30 $this->routes(function () {
31 Route::middleware('web')
32 ->namespace($this->namespace)
33 ->group(base_path('routes/web.php'));
34 
35 Route::prefix('api')
36 ->middleware('api')
37 ->namespace($this->namespace)
38 ->group(base_path('routes/api.php'));
39 });
40 }
41 
42 /**
43 * Configure the rate limiters for the application.
44 *
45 * @return void
46 */
47 protected function configureRateLimiting()
48 {
49 RateLimiter::for('api', function (Request $request) {
50 return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
51 });
52 }
53}

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 */
8public function pull($key, $default = null);
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 */
8public function pull($key, $default = null);

Testing

The decodeResponseJson Method

Likelihood Of Impact: Low

The decodeResponseJson method that belongs to the Illuminate\Testing\TestResponse class no longer accepts any arguments. Please consider using the json method instead.

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.

Comments

No Comments Yet

“Laravel” is a Trademark of Taylor Otwell.
The source documentation is released under MIT license. See laravel/docs on GitHub for details.
The translated documentations are released under MIT license. See cornch/laravel-docs-l10n on GitHub for details.