Answer the question
In order to leave comments, you need to log in
Why doesn't a one-to-many relationship work?
I can't figure out what the problem is. There is a table with users. And a table with orders.
There is a user_id field in the orders table, it refers to the user id in the user table.
I write a connection in the Order Model. This is how it works (if you specify user_id)
public function userId()
{
return $this->belongsTo('App\Models\User', 'user_id');
}
public function userId()
{
return $this->belongsTo('App\Models\User');
}
["foreignKey":protected]=>
string(10) "user_id_id"
Answer the question
In order to leave comments, you need to log in
Show a one-to-many relationship in the user model, something like this should look like an entry
public function contact()
{
return $this->hasMany(Contact::class,'user_id','id');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question