2

Can i create the first record in the database via migration, where in the passwordcolumn it is already bcrypted

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email');
        $table->string('level');
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });

    User::firstOrCreate([
        'name' => 'admin',
        'email' => 'admin@app.com',
        'level' => 'Administrator',
        'password' => 'password'
    ]);
}

the code is working but the password is not encrypted, any suggestion ?

Nico Aramy
  • 55
  • 7

2 Answers2

5

Save password in this way:

    'password' => Hash::make('password');

Or you can use this way:

'password' => bcrypt('password');
Faizan Ali
  • 297
  • 2
  • 9
0

To follow the pattern, it would be nice to create the first record in the database in a seed and not in the migration.