Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aleahy's avatar

That should be the xact code you have in your controller. The route model binding in the method parameter is equivalent to the find. You then just need to include $profile->load('photo.review');

If that doesn't work, it might be worth creating an API resource for photo as well. Where you include the review relationship if it has been loaded.

'photo' => PhotoResource::collection($this->photo),

So in your PhotoResource, you would have a line like this:

'review' => $this->whenLoaded('review')

That way, when you normally view photos without loading the review, it won't be included.

movepixels's avatar

@aleahy Yes now that I am able to get the data I have started on the additional resource

'photo' =>  PhotoResource::collection($this->photo),

Excellent and saved the day!

movepixels's avatar

@aleahy Thanks man! I got it working. I took a look at what you were saying and finally put it together the tinker examples had no id so we had to manually mimic it to get the profile, which the controller has

I cleared everything, deleted all reviewables and added some photos and pulled that user in the admin side and pretso photos with review(ables)

I greatly appreciate all your time, effort and patience!

aleahy's avatar

What about putting the photo in its own API Resource?

movepixels's avatar

@aleahy Yes I have added that PhotoResource and will carry on adding in other reviewable records in same fashion. An will take advantage of tinker moving forward. Not sure why i never bothered before but def will come in handy :)

Previous

Please or to participate in this conversation.