orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
137 stars 34 forks source link

Old value of Cropper on edit resource #68

Open HijenHEK opened 2 years ago

HijenHEK commented 2 years ago

Couldn't figure out how to get the old value of a custom attachment from certain model , i added the Attachable trait , and the attachments is working and i can get the default old values using Upload::value("attachment")

but i added a foreign key in my post model to set a default image ( featured image ) us the Cropper field but i can't preview it , apparently the Cropper::value() accepts the attachment url , and i couldn't link it to a relationship ( hasOne ) .

this is how i did resolve but it seems like a bad workaround :

PostResource

    private $post;

    public function __construct(Request $request)
    {
        $this->post =  (static::$model)::findOrFail($request->id);
    }
Cropper::make('featured_image')
                ->title('Featured  Image')
                ->width(500)
                ->height(300)
                ->horizontal()
                ->targetId()
                ->value( $this->post ? $this->post->featuredImage->url : true),

is there another way to do it? should i add this change by default in the resource class to always get the model instance from the url param?