How does Laravel generate all command-related files of the model migration controller?
P粉803444331
P粉803444331 2024-01-05 08:40:16
0
2
537

After these commands

php artisan make:model 'FileName' -mcs

Laravel make command file source (model, controller, migration, seeder, factory, etc...)

How are all the basic files generated and where do they come from?

P粉803444331
P粉803444331

reply all(2)
P粉833546953

These files are generated from stub files. Below are some stub directory locations on any Laravel project. You can check this out.

For models:

other:

If you want to control these stubs you must apply the following commands

This command will publish the stub files in the "stubs" folder of the project directory. You can then customize it to suit your needs.

P粉685757239

Everything generated in Laravel uses templates

If you run the artisan command in the console, you can observe that there is a section called Stub and the only command in that section is php artisan stub:publish.

If you run this command, it will generate a new folder called Stubs in your application root folder containing a bunch of files with a .stub extension.

You can open these files and modify or customize them as needed. From now on, your Laravel application will read in this folder templates for making various things that crafters typically make.

This template is included with every Laravel installation, and publishing them is completely optional. In fact, there are many software packages dedicated to making custom controllers or models, such as this one from Spatie p>

Internal structure above the generator Laravel has two cores,

  1. The first in application/console/kernel
  2. The second
  3. in app/Http/kernel

When you run artisan, Laravel bootstraps the application and runs the kernel console. The two kernels have different purposes and actually run as separate applications.

Regarding the specific generation of the above files, I mean different controllers, models, migrations, etc. Everything related to the model is generated from a class.

Class ModelMakeCommand extends GeneratorCommand{ .... }

Located under the Illuminate\Foundation\Console namespace.

You can inspect the code for this class and see how the stub files are used to generate only various commands related to the model, but there are many more, such as strategies, events, Homework etc...

I hope this helps you and answers your questions

Here is more information on this topicFrom Laravel News p>

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template