please how do i resolve this issue , the user table is in another database different from the seller database
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`seller`.`sellers`, CONSTRAINT `sellers_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE)
my livewire
$user = User::where('email', $this->email)->first();
if (!$user) {
// $studentNumber = $this->generateUniqueStudentNumber();
$user = User::on('second_db')->create([
'name' => $this->name,
'email' => $this->email,
'password' => bcrypt($this->password), // Correctly hash the password
]);
}
if (!$this->isStudent) {
$this->validate([
'nin' => 'required',
'state' => 'required',
'picture' => 'required|image',
]);
} else {
$this->validate([
'department' => 'required',
'schoolIdCard' => 'required|image',
]);
}
// Upload school ID card image
if ($this->isStudent) {
$schoolIdCardPath = $this->schoolIdCard->store('public/school_id_cards');
} else {
$picturePath = $this->picture->store('public/seller_pictures');
$schoolIdCardPath = null;
}
// Save seller to the database
// Seller::create([
// 'user_id' => $user->id,
// 'is_student' => $this->isStudent,
// 'department' => $this->department,
// 'school' => $this->school,
// 'school_id_card' => $schoolIdCardPath,
// 'picture' => $picturePath,
// 'state_id' => $this->state,
// 'business_name' => $this->business,
// 'nin' => $this->nin,
// 'address' => $this->address,
// 'whatsapp_number' => $this->whatsappNumber,
// 'verification_status' => false,
// ]);
$seller = new Seller();
$seller->setAttribute('user_id', $user->id);
$seller->setAttribute('state_id', $this->state);
$seller->is_student = $this->isStudent;
$seller->department = $this->department;
$seller->school = $this->school;
$seller->school_id_card = $schoolIdCardPath;
$seller->picture = $picturePath;
$seller->business_name = $this->business;
$seller->nin = $this->nin;
$seller->address = $this->address;
$seller->whatsapp_number = $this->whatsappNumber;
$seller->verification_status = 0;
$seller->save();
my model
class Seller extends Model
{
use HasFactory;
protected $connection = 'mysql';
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
}