I'm stuck on an issue where I'm trying to clean up code presented to me, and I feel like I must've just been at this too long and can't see this issue.
At the moment I have the following code in one of my models:
public function attachments(){
return $this->hasMany(volunteerAttachment::class, 'volunteerID','id');
}
public function photoID() {
$photoID= $this->attachments()->where('category','Drivers License')->orderBy('endDate','desc')->limit(1);
return $photoID;
}
What I would like to do is what I believed was relatively simple in replacing the limit(1)
of the function photoIdentification
with a simple first()
.
But when I try that and simply put in my blade, it simply returns the error App\volunteer::photoID must return a relationship instance
.
I do however know that there is a relationship because if I continue to use the limit(1)
and put:
@foreach($volunteer->photoID as $id)
@endforeach
It returns the relation and document correctly. I'd appreciate any help. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire