Place the following values in the .env file.
INITIAL_USER_PASSWORDHASH is bcrypt and has to be generated by the users.
You can use https://bcrypt-generator.com/ as a online generator tool to create passwords outside of the application.
Your application should provide an easier way.
You don't want to save cleartext passwords in the env file.
INITIAL_USER_NAME=
INITIAL_USER_EMAIL=
INITIAL_USER_PASSWORDHASH=
Then as suggested in the other answers before use a seeder:
To generate a seeder with composer you will need to use the following artiasn command.
php artisan make:seeder UsersTableSeeder
This command will create a seeder file located in your database/seeds folder.
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
'name' => env('INITIAL_USER_NAME'),
'email' => env('INITIAL_USER_EMAIL'),
'password' => env('INITIAL_USER_PASSWORDHASH'),
]);
}
}
You will need to edit your database/seeds/DatabaseSeeder.php and make sure UsersTableSeeder::class is uncommitted inside the method run().
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call([
UsersTableSeeder::class
]);
}
}
It is recommended you run the composer dump-autoload command after saving your changes.
You can run all seeds that are inside the DatabaseSeeder.php file by running the artisan command;
php artisan db:seed
You can alternatively use the following to execute only the one seeder by doing the php artisan db:seed --class="UsersTableSeeder" command.
You can also use php artisan migrate:fresh --seed to do a fresh migration of your database tables and seed the table in a single command.