How to use shell script to execute laravel routing in centos7?
phpcn_u1582
phpcn_u1582 2017-05-16 16:47:35
0
3
518

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.

phpcn_u1582
phpcn_u1582

reply all(3)
黄舟

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 script

淡淡烟草味

You can use shell to simulate local browsing

curl http://localhost/XX/init-users
curl http://localhost/XX/init-roles
#....
#....

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!