zwl1619
zwl1619

Reputation: 4232

How to run Laravel's routes with shell script of linux?

I am using Laravel on centos 7,I have some routes that are used to initiate some data,like this:

Route::get('init-users', 'InitController@initUsers');
Route::get('init-roles', 'InitController@initRoles');
//...
//...
//...

I want to write a shell script file to run the routes above,what command should I use to do it?

Upvotes: 0

Views: 358

Answers (1)

FatBoyXPC
FatBoyXPC

Reputation: 951

While you could use curl to accomplish this, Laravel actually has built in functionality for this, called Seeding.

Essentially, you'd do something like this:

php artisan make:seeder UsersTableSeeder

Then edit your UsersTableSeeder file:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('secret'),
        ]);
    }
}

Then finally: php artisan db:seed

Follow the link above for more information about it, as I gave you a very basic example.

Upvotes: 3

Related Questions