Artikel ini akan membahas langkah-langkah upgrade project laravel 10 ke laravel 11 untuk project yang sedang berjalan.
Laravel 11 rilis 12 Maret 2024, membawa perubahan cukup besar. Namun update laravel 11 ini tidak merubah syntak koding ya, tim laravel lebih kearah merampingkan struktur folder framework. Yaps, laravel 11 bisa menyesuaikan peruntukan dari project yang akan kita kembangkan, mau menjadi full stack atau hanya API saja.
Proses upgrade dari laravel 10 ke laravel 11 untuk project yang sudah ada, menurut saya ada 2 tahapan, yaitu :
- Updating Dependencies
- Application Structure
Updating Dependencies
Laravel 11 berjalan pada PHP versi 8.2 (minimal).
Buka file composer.json dan update dependencies sesuai yang kalian gunakan sekarang. sesuaikan versinya seperti dibawah ini :
- laravel/framework to ^11.0
- nunomaduro/collision to ^8.1
- laravel/breeze to ^2.0 (If installed)
- laravel/cashier to ^15.0 (If installed)
- laravel/dusk to ^8.0 (If installed)
- laravel/jetstream to ^5.0 (If installed)
- laravel/octane to ^2.3 (If installed)
- laravel/passport to ^12.0 (If installed)
- laravel/sanctum to ^4.0 (If installed)
- laravel/spark-stripe to ^5.0 (If installed)
- laravel/telescope to ^5.0 (If installed)
- inertiajs/inertia-laravel to ^1.0 (If installed)
Beberapa packages seperti Laravel Cashier Stripe, Passport, Sanctum, Spark Stripe, dan Telescope kita perlu publish vendor untuk file migrationnya. Ini perlu dilakukan jika kita menggunakan package tersebut.
php artisan vendor:publish --tag=passport-migrations
php artisan vendor:publish --tag=sanctum-migrations
php artisan vendor:publish --tag=spark-migrations
php artisan vendor:publish --tag=telescope-migrations
Finally, hapus packagedoctrine/dbal pada composer (jika ada) karena laravel sudah tidak bergantung pada package tersebut.
Application Structure
- Hapus app/Console/Kernel.php
- Hapus app/Exceptions/Handler.php
- Hapus file pada folder Middleware (app/Http/Middleware)
- Update file index.php pada folder public
<?php
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__ . '/../storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__ . '/../vendor/autoload.php';
// Bootstrap Laravel and handle the request...
(require_once __DIR__ . '/../bootstrap/app.php')
->handleRequest(Request::capture());
- Buat file bootstrap/providers.php
<?php
return [
App\Providers\AppServiceProvider::class,
];- Update bootstrap/app.php , Update core nya disini.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// your middleware
})
->withExceptions(function (Exceptions $exceptions) {
// your exception
})->create();