I'm sure there is an easy solution to this, but for whatever reason, I just can't seem to crack it. I'm using Laravel 5.3 for reference.
I have a User model (using Laravels Auth scaffolding) with a relationship to Artwork
public function artworks()
{
return $this->hasMany('App\Artwork');
}
My artwork model has a belongsTo relationship to the User
public function user()
{
return $this->belongsTo('App\User');
}
I want to display all of the uploaded artwork in the Admin panel, but I want it to also include the owner of the artwork. So, this works fine:
$a = Artwork::orderBy('id', 'asc')->simplePaginate(1);
Then in my view, I do:
@foreach($a as $art)
{{$art->user->name}}
@endforeach
Now, this works fine as well. However, if I try to change the order to DESC, I get Trying to get property of non-object. What am I missing? I've only been using Laravel for about a week, so please excuse my ignorance in advance, and thanks for your help!