Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] crud-api doesn't work properly with upload fields. #5644

Closed
rezahmady opened this issue Aug 31, 2024 · 1 comment
Closed

[Bug] crud-api doesn't work properly with upload fields. #5644

rezahmady opened this issue Aug 31, 2024 · 1 comment
Assignees
Labels
Possible Bug A bug that was reported but not confirmed yet.

Comments

@rezahmady
Copy link

rezahmady commented Aug 31, 2024

Bug report

What I did

in store method i want to change field :
my field :

[
    'name'  => 'logoImage',
    'label' => trans("serial::lang.video_logo_image"),
    'type' => 'image',
    'withFiles' => [
        'disk' => $static_disk,
        'path' => 'images',
    ],
    'wrapper'   => [
        'class'  => "form-group col-md-6 ltr"
    ],
    'fake'  => true,
    'tab'   => trans('vod::lang.video_images_tab'),
],

i want to change field value :

$crud->getRequest()->request->add([
    'imagePoster' => $value,
]);

or

$this->crud->modifyField('imagePoster', [ 'value' => $value]);

This api works well with fields that do not have the withFiles attribute

What I expected to happen

field value save correctly.

What happened

field value is null.

I know that you are working on the redesign of the upload field, but this issue is very important to me and I cannot wait until you finish that task. If possible, check and fix this issue.

@pxpm pxpm added Possible Bug A bug that was reported but not confirmed yet. and removed triage labels Oct 15, 2024
@pxpm pxpm moved this to Todo in This week Oct 15, 2024
@karandatwani92
Copy link
Contributor

karandatwani92 commented Oct 21, 2024

Hey @rezahmady

I just tested it, and it works for me. Here is what I did:

  1. Followed the guide
  2. Used the following code to modify the image on the fly.
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation { update as traitUpdate;}

public function update(){
    $single_pixel_base64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==";
     // modify image before saving
    $this->crud->getRequest()->request->add(['main_image' => $single_pixel_base64]);
    $response = $this->traitUpdate();
    // do something after update
    return $response;
}

public function store(){
    $single_pixel_base64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==";
   // modify image before saving
    $this->crud->getRequest()->request->add(['main_image' => $single_pixel_base64]);
    $response = $this->traitStore();
    // do something after save
    return $response;
}

Field Definition:

CRUD::field('main_image')
    ->label('Main Image')
    ->type('image')
    ->tab('Media')
    ->wrapper(['class' => 'form-group col-md-4'])
    ->fake(true)
    ->withFiles(['path' => 'images']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Bug A bug that was reported but not confirmed yet.
Projects
Status: Done
Development

No branches or pull requests

3 participants