In your code, there's no condition that checks if the user is farmer or buyer.
You need to make a condition for identity user is farmer or buyer.
Please try below code. Hope its work for you.
$user = User::create([
'username' => $data['username'],
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'group' => $data['group'],
]);
if( $data['group'] == 'farmer'){
$farmer = Farmer::make([
'user_id' => $user->id,
]);
$user->farmer()->save($farmer);
}else{
$buyer = Buyer::make([
'user_id' => $user->id,
]);
$user->farmer()->save($farmer);
}
return $user;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community