KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Images in AdminTable #2471

Open Wayland Games opened this topic on on Dec 1, 2021 - 4 comments

Wayland Games commented on Dec 1, 2021

Think this is a bug but not 100% sure...

Within a Resource we have an Image field declared thus:

        Image::create('avatar')
            ->accept(['jpg'])
            ->saveToFolder('assets/avatars')

With the field declared in this way the file is stored in the correct folder and the CreateAction and UpdateAction default functions display the file correctly on Create and Update.

However the table is looking only for the filename (which is what's stored in the database) of the image, not prepended with the declared saveToFolder location as appears to be happening within the Create/Update functions.

If I add a processValueToDatabase function and return 'assets/avatars' . $filename then the table renders the image correctly but the Update and Create functions don't as assets/avatars is added twice.

Is this the intended behaviour?

KoolReport commented on Dec 1, 2021

You use the resolveUsing() like this:

Image::create("avatar")
    ->resolveUsing(function($filename){
        return "assets/avatars/$filename";
    })

Please let me know.

Wayland Games commented on Dec 1, 2021

Declaring the field:

        Image::create('avatar')
            ->accept(['jpg'])
            ->saveToFolder('assets/avatars')
            ->resolveUsing(function($filename){
                return "assets/avatars/$filename";
            })

Has it working in the table and within the create action but the edit action is duplicating the assets/avatars.

File's ending up in the correct place, only the filename is written to the DB as expected.

If I remove the savetofolder it errors out, as it doesn't have authority to save images to the same directory as the script.

KoolReport commented on Dec 1, 2021

Alright, let not use resolveUsing() but use formatUsing(). Please let me know.

Wayland Games commented on Dec 1, 2021

Ah ha! That's resolved it, thanks for your assistance.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard