how to catch seeder data from model when seeding
here is my seeding data -
public function run(): void
{
$data = [];
$data['name'] = 'test';
$data['email'] = '[email protected]';
$data['phone'] = 01929111222;
\App\Models\User\User::create($data);
}
i want to catch the phone number from "User" model when this seeder will run. but i dont know how to do this.
User model - (example)
public static function boot()
{
parent::boot();
self::creating(function($user)
{
if(request()->password){
$user->password = bcrypt(request()->password);
}
else{
dd(request()->phone);
$user->password = bcrypt(request()->phone);
}
});
}
There is no Request, so request() makes no sense in this context.
You will get the password and or phone property on the User instance itself
if($user->password) {
$user->password = bcrypt($user->password);
} else {
$user->password = bcrypt($user->phone);
}
Make sure Model events are not muted
Please or to participate in this conversation.