I want to display through the user's photo relationships but it does not show And this photo also exists, but when I take dd(), it says null this is Blade code And they all work except the user_image
@foreach($threads as $thread)
<div >
<div >
<blockquote >
<div >
<p style="font-size: x-large; font-weight: bold; "><a href="/threads/{{$thread->slug}}">{{\Illuminate\Support\Str::limit($thread->title,50)}}</a>
</p>
</div>
<div >
<img style="width: 60px; height: 60px;"
src="{{$thread->user->user_image}}"> {{-- this is not working--}}
<p
توسط {{$thread->user->name}} آپدیت شد</p>
</div>
<footer
>{{\Illuminate\Support\Str::limit($thread->description,150)}}
</blockquote>
</div>
</div>
@endforeach
CodePudding user response:
Maybe replace
public function user()
{
return $this->belongsTo(User::class);
}
by something like
public function images()
{
return $this->belongsTo(User::class);
}
and for users do
hasMany (images)
Also you have to do migrations to add foreign keys, did you do this ?
CodePudding user response:
@sachin kumar Sir it is my Thread model and the relation is true because when I display
{{$thread->user->name}}
or
{{$thread->user->email}}
it is working but I do not know why its doesnt working for image?!
public function user()
{
return $this->belongsTo(User::class);
}
