1

Is there a way to render image directly from base64 code in Laravel backpack CRUD view without converting it to image file?

My reason for this is to not consume disk space. I tried viewing the documentation but only the saving of the base64 code is shown.

Thanks.

--edit--

I already have this code on my CRUD controller:

$this->crud->addColumn([ // base64_image
                'label' => "Signature",
                'name' => "signature_data",
                'filename' => NULL, // set to null if not needed
                'type' => 'base64_image',
                'aspect_ratio' => 0, // set to 0 to allow any aspect ratio
                'crop' => false, // set to true to allow cropping, false to disable
                'src' => NULL, // null to read straight from DB, otherwise set to model accessor function
        ]);

signature_data field is set to LONGBLOB

But it only displays the base64 code in the CRUD view:

enter image description here

2 Answers 2

0

Try to change signature field in CRUD view file:

<td>
<img src="{{signature field name here}}" width="100" height="100"/>
</td>
Sign up to request clarification or add additional context in comments.

1 Comment

is this a custom view file? it seems that I cant find it on the built-in view file.
0

There is no default base64_image column type in Backpack (all columns here in docs). So Backpack just treated your column type as text. Since it's a "text" column, it shows the first characters of your blob.

You can create a custom column type that shows your image from the base64 string. Consider re-using the image.blade.php file - Backpack does have an image column type that shows images from an URL.

Background: There have been talks regarding a base64_image column type some time ago - some suggested adding it in the core (because it would be intuitive), others motioned against it, because we should probably discourage people from storing images as base64 strings in the database. I'm still torn, but leaning towards having it. If you do create the column type for yourself, consider submitting a PR with it - that way the discussion is reopened and we might include it in the core.

1 Comment

but I saw this one though github.com/Laravel-Backpack/CRUD/blob/master/src/resources/… and also this: backpackforlaravel.com/docs/3.4/crud-fields#base64_image can you confirm if this is not an actual feature?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.