Support the ongoing development of Laravel.io →
Eloquent Architecture Database
Last updated 1 year ago.
0

In your code, there's no condition that checks if the user is farmer or buyer.

0

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;
Last updated 4 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Heru Gunawan bnhr Joined 4 Jul 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.