E
E
Emil Rakhmatullin2021-01-07 17:45:35
Laravel
Emil Rakhmatullin, 2021-01-07 17:45:35

How to use artisan commands when creating Laravel 7 package?

Let's say I'm building a Laravel 7 package. How do I use the Laravel 7 artisan commands to create models, migrations, controllers, policies, etc.? for your package (in its directory)?

I did not find this information in the documentation.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Chubarov, 2021-01-07
@Emchik

Consider an example where you are developing your package locally.
A folder is created at the root of the project and an entry is added to composer.json like this

"repositories": [
    {
      "type": "path",
      "url": "author/package"
    }
  ]

More details can be found here in the documentation
. With this setting, the package will create a link in the vendor.
As for the standard commands in Laravel (artisan), everything is individual here, for example, migration can be added to your package with such a command
php artisan make:migration name_migration --path=author/package

In the command to create factories, databasePath is taken as the root, get out of the situation in the following way.
- Depending on the context, change the base path
- Inherit or create your own command to form the path when creating the factory
I myself, in such cases, simply created the files with my hands.
After looking at several ready-made packages for developing packages for Laravel, I did not find such a feature, and in one of them they offer to create it through the usual artisan and simply copy it into your package.
You can also use the console:
php artisan make:controller OurController && mv app/Http/Controllers/OurController.php author/package/pathWhereControllerStore

Accordingly, you can create an alias and write less, or you can script where the namespace will still change in accordance with your package.

S
Sanes, 2021-01-07
@Sanes

For modularity here .
There is nothing special about the composer. Maybe here .

K
Konstantin B., 2021-01-07
@Kostik_1993

Do you understand what you want?)
Maybe you just need to create your own console commands? And nothing can be generated in the packages folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question