How to use shell script to execute laravel routing in centos7?
After executing php artisan migrate to generate the data table, some initial data needs to be generated.
So I wrote an InitControler, which contains some methods for generating some initial data.
After writing, I will access the method of this controller by accessing the route. The route is as follows:
Route::get('init-users', 'InitController@initUsers');
Route::get('init-roles', 'InitController@initRoles');
//...
//...
//...
Question:
I want to write a shell script to access these routes instead of manually inputting the routes into the browser and pressing Enter. How should I write this shell script? Please help me write it.
By custom command of course
php artisan make:console FooCommand
Write the code logic in FooCommand.php, then execute it through
php artisan
and write it in the shell scriptYou can use shell to simulate local browsing
However, this requires that the website can be accessed locally
How about I change my mind
That is, instead of writing the initialization data to C, I write it to the migration file.
Normally, each data table will correspond to a migration file. You can write the initialization data for the table to a private method. After the up method of the migration itself, use $this->xxx() to call it. That’s it.
This has several advantages: the initialization data will be initialized at the same time as the migration, and the initialization data is neatly divided into the corresponding migration tables.
P.S. Because each migration also corresponds to a Model
, you can also use the model to initialize data. Not so cool.