PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] Laravel create first record with Bcrypt password

 February 16, 2022     bcrypt, database, laravel, migration     No comments   

Issue

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 ?


Solution

Save password in this way:

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

Or you can use this way:

'password' => bcrypt('password');


Answered By - Faizan Ali
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing