This article is an updated version of Laravel 7 package development article
Step 1. Create a new project
I prefer using the Laravel installer. You can read more about the installation here: https://laravel.com/docs/10.x/installation
laravel new lara-dg
I prefer using SQLite for testing and package development. Adjust your.env file
Then let’s create our package skeleton. We will be using a CLI tool. It will generate all necessary files
composer require jeroen-g/laravel-packager
Then you can run generation command. Webkid stands for vendor name(your namespace) and LaravelDiagnostic as the name of your project
php artisan packager:new Webkid LaravelDiagnostic --i
Then type information about your package and you. It should look like that
Now you have packages folder inside of your project with Webkid directory inside and all necessary files inside.
This package is automatically loaded via composer. I prefer using a relative path:
Also, update your require section if it wasn’t updated automatically. It will create a symlink in your vendor directory to your package directory
Now you can create classes inside the src folder, but they should have appropriate namespace Webkid\LaravelDiagnostic.
For example, I have Commands folder and RunDiagnostic.php class inside. So it should have such namespace:
If you want to use your migrations, routes, config files, views, or even assets(js, CSS, images), you have to load them in your service provider. You can read about that in the official documentation. I was using only commands in my example. Take…