We don't know. Provide us with more details.
Laravel backpack Multiple Image preview in edit form not working
Hello,
$this->crud->addField([
'name' => 'roomBanner_image',
'label' => 'Room Banner Image',
'type' => 'upload_multiple',
'upload' => true,
],'both');
Above is the code to add multiple images. i have added roomBanner_image in cast .
protected $casts = ['roomBanner_image' => 'array'];
But when i click on edit , I get set selected images on a seperate div above the input field of roomBanner. Why is this happening? Please Help.
public function setRoomBannerImageAttribute($value)
{
$multipleimage = $value;
$saveImage = [];
foreach ($multipleimage as $key => $multipleImage) {
if(empty($multipleImage)){
$input['roomBanner_image'] = "";
}else{
$input['roomBanner_image'] = $multipleImage->getClientOriginalName();
$img = \Image::make($multipleImage->getRealPath());
$destinationPath = public_path('/uploads/thumbnailImages');
$img->resize(750, 450, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['roomBanner_image']);
$destinationPath = public_path('/uploads/thumbnailImages');
$img->resize(100, 100, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['roomBanner_image']);
$multipleImage->move($destinationPath, $input['roomBanner_image']);
$saveImage[$key] = $input['roomBanner_image'];
}
}
$saveImage = json_encode($saveImage);
$this->attributes['roomBanner_image'] = $saveImage;
}
I have used the above code to upload multiple file which is storing json array in the database. ["abc.png","zyd.png"].
$this->crud->addColumn([
'name' => 'roomBanner_image',
'label' => 'Room Banner Image',
'type' => 'array'
]);
Used the above code to display data to the view table.
When i click on edit, i can see the existing data above the input field of roomBanner and not within it. It is creating a separate div above roomBanner input field. Please Help.
Anyone there??
can you show us your form?
I haven't use any form. I have used laravel backpack. So, when i click on edit a form opens with values exisitng in which multiple images are previewing on top of the div and input field value is null. hope u r getting me?
I just have a model function which does all the work for me. data is being stored in json array. but when retrieving in the edit form input field value is null and images are preivewd on top. Please help
i am getting your point .. I also use Laravel Paperclip for uploading images. we have a model in that which does all the work, we still create a form for uploading images. but how are you uploading images? you said you are not using any form. how is it uploading the images.
public function setRoomBannerImageAttribute($value)
{
$multipleimage = $value;
$saveImage = [];
foreach ($multipleimage as $key => $multipleImage) {
if(empty($multipleImage)){
$input['roomBanner_image'] = "";
}else{
$input['roomBanner_image'] = $multipleImage->getClientOriginalName();
$img = \Image::make($multipleImage->getRealPath());
$destinationPath = public_path('/uploads/thumbnailImages');
$img->resize(750, 450, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['roomBanner_image']);
$destinationPath = public_path('/uploads/thumbnailImages');
$img->resize(100, 100, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['roomBanner_image']);
$multipleImage->move($destinationPath, $input['roomBanner_image']);
$saveImage[$key] = $input['roomBanner_image'];
}
}
$saveImage = json_encode($saveImage);
$this->attributes['roomBanner_image'] = $saveImage;
}
using the above code to upload the images to folder. ["abc.png","xyz.png"] in my database.
i get it @Kavyajain
you must have created an Edit function too... isn't it? @Kavyajain
no. edit i havnt created. using resource crud controller.
So basically, the field name is exactly the column name. so expecting it to override the variable values. But it is not.
Please or to participate in this conversation.