search

Home  >  Q&A  >  body text

How to use shell script to execute laravel routing in centos7?

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_u1582phpcn_u15822753 days ago549

reply all(3)I'll reply

  • 黄舟

    黄舟2017-05-16 16:49:35

    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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 16:49:35

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:49:35

    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.

    reply
    0
  • Cancelreply