The Laravel Application Is All Packaged Up!
The exercise of updating all my LaSalle Software live and test apps to the new Laravel 8 was daunting. So daunting that a back-burner idea seemed worth exploring: turning the entire Laravel app repository into a package.
What if all I had to do to upgrade my LaSalle Software app (front-end and back-end apps) to the latest Laravel version was update one single package, update the app's composer.json, then run composer update package-name. Wouldn't that be wonderful! No more hand updating each individual app -- the app itself -- with the necessary code changes.
Turns out that this can be done. Not completely. But "thin app, thick package" is very do-able.
The LaSalle Software front-end and back-end apps already have this package included in its composer.json.
This package is required:
What steps did I take to package up the Laravel app?
COMPOSER.JSONMove the following "require" to the package:
"fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "laravel/framework": "^8.0", "laravel/tinker": "^2.0"
Replace the above with:
BOOTSTRAP/APP.PHPChange the "Bind Important Interfaces" section of "bootstrap/app.php" from:
$app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class ); $app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class );
$app->singleton( Illuminate\Contracts\Http\Kernel::class, Lasallesoftware\Laravelapp\Http\Kernel::class ); $app->singleton( Illuminate\Contracts\Console\Kernel::class, Lasallesoftware\Laravelapp\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, Lasallesoftware\Laravelapp\Exceptions\Handler::class );
The three Laravel app classes are replicated exactly in the package.
"app/Http/Kernel.php" is deleted.
"app/Console/Kernel.php" is deleted.
APP/HTTP/MIDDLEWAREAll the middleware classes in "app/Http/Middleware" are replicated in the package, and deleted in the app.
The middleware namespaces are changed to the package's namespace in "Lasallesoftware\Laravelapp\Http\Kernel.php".
ROUTES/*The app's "routes" folder replicated in the package, then deleted in the app.
CONFIG/APP.PHPChange the "Bind Important Interfaces" section of "bootstrap/app.php" from:
/* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class,
/* * Application Service Providers... */ Lasallesoftware\Laravelapp\Providers\AppServiceProvider::class, Lasallesoftware\Laravelapp\Providers\AuthServiceProvider::class, // Lasallesoftware\Laravelapp\Providers\BroadcastServiceProvider::class, Lasallesoftware\Laravelapp\Providers\EventServiceProvider::class, Lasallesoftware\Laravelapp\Providers\RouteServiceProvider::class,
The service providers are replicated exactly in the package.
The "base_path()" in these classes are modified to use the package's routes, not the app's routes.