0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.