If you’re currently using Laravel 9.x for your website or bespoke web app, it’s crucial to stay ahead of the curve and upgrade to Laravel 10.x, which was released on February 14, 2023. This ensures that your system remains secure and benefits from the latest features. In this guide, we’ll walk you through the essential steps to seamlessly upgrade from Laravel 9.x to Laravel 10.x while preserving the
Ensure that your system runs PHP 8.1.0 or later, as Laravel 10.x mandates this version. Check your PHP version using the command:
./vendor/bin/sail php -v
Update dependencies in your composer.json file:
“laravel/framework”: “^10.0”, “laravel/sanctum”: “^3.2”, “doctrine/dbal”: “^3.0”, “spatie/laravel-ignition”: “^2.0”, “laravel/passport”: “^11.0”
If using PHPUnit 10, remove processUncoveredFiles from your phpunit.xml configuration:
“nunomaduro/collision”: “^7.0”, “phpunit/phpunit”: “^10.0”
Update any third-party packages to match Laravel 10.x requirements.
Ensure that the minimum-stability in your composer.json is set to “stable” or remove the setting if it’s set by default.
“minimum-stability”: “stable”
Modify the code invoking usePublicPath for a customized ‘public path’:
app()->usePublicPath(__DIR__.’/public’);
Use Laravel’s new cache:prune-stale-tags function to handle Redis cache tag support efficiently. Add this Artisan command to your App\Console\Kernel class:
$schedule->command(‘cache:prune-stale-tags’)->hourly();
Rewrite database expressions using DB::raw. Update manually casted database expressions to invoke the getValue method.
use Illuminate\Support\Facades\DB; $expression = DB::raw(‘select 1’); $string = $expression->getValue(DB::connection()->getQueryGrammar());
Adjust code if your application manually throws
Illuminate\Database\QueryException.
Specify column name when invoking the ULID method during migration:
$table->ulid(‘ulid’);
Replace the deprecated $dates field with the $casts property:
protected $casts = [ ‘deployed_at’ => ‘datetime’, ];
Remove the getBaseQuery method on the
Illuminate\Database\Eloquent\Relations\Relation class.
Upgrade Monolog to version 3.x if your application interacts directly with Monolog.
Replace obsolete approaches Bus::dispatchNow and dispatch_now with Bus::dispatchSync and dispatch_sync.
Rename $routeMiddleware to $middlewareAliases in App\Http\Kernel.
Handle returned values when executing RateLimiter::attempt method.
Replace deprecated Redirect::home with explicit route redirection:
return Redirect::route(‘home’);
Replace deprecated MocksApplicationServices trait with Event::fake, Bus::fake, and Notification::fake.
Adjust closure-based custom validation rules using the $fail callback.
Check the Laravel GitHub repository for more changes and updates. Some updates are optional but recommended for a smooth transition.
Thoroughly read the Laravel 10.x documentation before upgrading to minimize the risk of technical issues. For expert assistance in Laravel development, Tec Sense offers comprehensive services, from customization to maintenance. Contact us for a free quote at sales@tec-sense.com.