Open asadkamran opened 1 year ago
#table schema
create table vehicle_images (
id int auto_increment primary key,
vehicle_id int,
img varchar(255),
img_type varchar(20),
created_at datetime,
updated_at datetime
)
# in form
$form->hasMany('vehicleImages', __('content'), function($form){
$form->text('img_type', __('type'))->attribute('maxlength', 32)->rules('required');
$form->image('img', __('img'))->name(function($file){
$rand = rand(0, 1000);
return "{$rand}-".$file->getClientOriginalName();
});
});
that's it.
Thank you for providing a solution. i see it may help in case we add note/description with image.
It may help some one, to achieve i created 2 models, Model 1: `namespace App\Admin\Models;
use Illuminate\Database\Eloquent\Model;
class VehicleInteriorImage extends Model { protected $table="vehicle_images"; /**
@var array */ protected $fillable = [ 'id','vehicle_id', 'file','sorder','type', 'status', ];
public function save(array $options = array()) { if( ! $this->type) { $this->type = 2; }
parent::save($options);
}
} `
Model 2: ` namespace App\Admin\Models;
use Illuminate\Database\Eloquent\Model;
class VehicleExteriorImage extends Model { protected $table="vehicle_images"; /**
@var array */ protected $fillable = [ 'id','vehicle_id', 'file','sorder','type', 'status', ];
public function save(array $options = array()) { if( ! $this->type) { $this->type = 1; }
parent::save($options);
}
} `
` $form->multipleImage('vehicleExteriorImages',('Exterior Image'))->pathColumn('file')->sortable()->move('vehicles')->uniqueName()->removable(); $form->multipleImage('vehicleInteriorImages',('Interior Image'))->pathColumn('file')->sortable()->move('vehicles')->uniqueName()->removable();
`
Description:
ITS NOT ISSUE, JUST A PROBLEM I AM FACING.
How i can set the 'type' field value in vehicle_images table to 'exterior_image', so i can identify its exterior or interior images, i am using multipleImage, and wants to upload exterior and interior image separately.
in Vehicles Model:
In Vehicle Controller:
my goal is to set type ('interior_image' or 'exterior_image') for each image uploaded.