How Laravel Generate Model Migration Controller all command related files?


after these commands

php artisan make:model 'FileName' -mcs

Laravel make command files sources (Model, Controller, Migration, Seeder, Factory etc…)

How all basic files generate and where from these files comes?


All the generated stuff in Laravel use templates

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

If you run that command it will generate a new folder inn your app root folder called stubs with a bunch of files inside all with extension .stub.

You can open those files and modify then or customize them as needed. From now on this folder will be the place from where your Laravel app will read the template for making all kind of stuff that artisan usually does.

This templates are included with every Laravel installation and is totally optional publish them or not. In fact there are many packages dedicated to make custom Controllers or Models like this one from Spatie

The internals above this generators
Laravel has two kernels,

  1. The first one in app/Console/kernel
  2. The second one in app/Http/kernel

When you run artisan, Laravel Bootstrap the app, and run the Kernel console. This both Kernels has different purposes, really they function as separates apps.

About the specific generation of the above files, I mean different controllers, Models, migrations etc.. all that stuff related to models are generated by one Class.

class ModelMakeCommand extends GeneratorCommand{ .... }

Which is located under Illuminate\Foundation\Console namespace.

You can check the code of that class and see how the stubs files are used to generate the variety of commands only related to Models, but there are many more, like Policies, Events, Jobs etc…

I hope this helps and answer your question

Here you are more information about this subject from Laravel News

Answered By – Manuel Glez

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published