Introduction

In this tutorial, we will store an admin's name, email, and password in the .env file, for quickly spinning up a new admin, user. Optionally, we can set different credentials based on development environments.

Add the following variables to your .env file:

ADMIN_NAME="Billy B."
ADMIN_EMAIL=billy@gmail.com
ADMIN_PASSWORD=password

{info} Also, add the above variables, without values, to the .env.example file for reference, and finally, add a corresponding notes in the readme file.

Next, create a new file under /config/ directory, and call it admin.php.

<?php
return [
    'admin_name' => env('ADMIN_NAME', ''),
    'admin_email' => env('ADMIN_EMAIL', ''),
    'admin_password' =>env('ADMIN_PASSWORD', '')
    ];

Next, create a database seeder:

php artisan make:seeder NovaUserSeeder

Modify the seeder

<?php

use App\User;
use Illuminate\Database\Seeder;

class NovaUserSeeder extends Seeder
{
    public function run()
    {
        if (config('admin.admin_name')) {
            User::firstOrCreate(
                ['email' => config('admin.admin_email')],
                [
                    'name' => config('admin.admin_name'),
                    'password' => bcrypt(config('admin.admin_password')),
                ]
            );
        }

    }
}

Add the following code to run() method to your database/seeds/DatabaseSeeder.php:

$this->call(NovaUserSeeder::class);

Refresh and seed the database

composer dump-autoload
php artisan migrate:refresh --seed

// or

php artisan db:seed --force