Home > database >  Create database with initial data in Laravel running project
Create database with initial data in Laravel running project

Time:04-20

I have a running project from another server. I installed it locally on my machine with an admin username and password. However, I ran a command that deleted all my database information, so it's returned to fresh databases. Is there any method to get the initial databases?

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // Create Roles
        $roles = ['admin', 'instructor', 'student', 'parent', 'guest', 
            'employee', 'institute', 'candidate'];

        foreach ($roles as $role) {
            Role::create(['name' => $role]);
        }
    }

    // Create user and assign admin role 
    $user = User::create([
        'first_name' => 'QwikTest',
        'last_name' => 'Admin',
        'user_name' => 'admin',
        'email' => '[email protected]',
        'password' => Hash::make('password'),
        'email_verified_at' => Carbon::now()->toDateTimeString()
    ]);

    $user->assignRole('admin');
}

CodePudding user response:

The command for seeding is this:

php artisan db:seed

or, with fresh migration:

php artisan migrate:fresh --seed

CodePudding user response:

Personally, I'd grab a full database backup from production either through workbench or phpmyadmin. Then just add that backup to your local database. No migrations to run and good data to play with. Your admin password locally will be the same as production.

  • Related