Im wondering if I could get some advice.
In my blade template, i have the following;
<a href="#">{{ $gallery->creator->name }}</a>
My controller looks like this;
public function show(Gallery $gallery)
{
return view('galleries.show', compact('gallery'));
}
The next bit is where im having some trouble, In my model i have the following relationship
public function creator()
{
return $this->belongsTo(User::class, 'user_id');
}
Some of the galleries have a null user_id value as they are not logged in when posted.
Is there a way that I can set the $gallery->creator->name to 'Anonymous' if the user_id is null, but if there is a value, use whats already there? Any help making a mutator would be awesome
Any help would be greatly appreciated.
Cheers,