How to access attached Picture in Model #1488
Unanswered
mik3lov3st3ch
asked this question in
Q&A
Replies: 1 comment
-
Hi @mik3lov3st3ch, you can use the relation to one in your model. For example: use Orchid\Attachment\Models\Attachment;
public function image()
{
return $this->hasOne(Attachment::class, 'id', 'image')->withDefault();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I´ve added an image as attachment for a Model as follows:
Picture::make('product.image')->title('Product image')->targetId()
Now I´ve the new attribute "image" for my product model. However, I want to access the whole object - at the moment I can only retrieve the ID of the attachement with the "image" attribute. I´ve tried to access the image object by defining it as a relation in the Product model, however that didn´t work.
Has anyone an example on how to access the image object in the model? Especially the URL to the image is important, cause I have to pass it to my GraphQL API.
Thanks,
Michael
Beta Was this translation helpful? Give feedback.
All reactions