Answer the question
In order to leave comments, you need to log in
Why doesn't Laravel see a simple model relationship?
Feedback model:
class Reviews extends Model
{
protected $timestamp = false;
public function user() {
return $this->hasOne('Users', 'id', 'user');
}
}
@foreach($reviews as $review)
<div class="card">
{{$review->user->firstName}}
{{$review->text}}
</div>
@endforeach
Answer the question
In order to leave comments, you need to log in
name everything correctly
The model should be called not Reviews but Review
user is this property Reviews ? Is it the id from the users table? then you need to call user_id
then it would be
public function user() {
return $this->hasOne('App\User', 'id', 'user_id');
}
public function user() {
return $this->belongsTo('App\User', 'user_id', 'id');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question