I have edit blade file in my laravel application. in this edit form update data saving to two tables to vehicles and uploads. I have following codes in edit blade file update images to uploads table,
@foreach( $vehicles-> uploads as $upload)
<img id="preview"
src=""
height="200px" width="200px"/>
<input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="" enctype="multipart/form-data">
<br/>
<a href="javascript:changeProfile();">Add Image</a> |
<a class="button is-outlined" href="/myads//delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>
<hr>
@endforeach
@endif
update controller is,
$photos = $request->file('files');
if (!is_array($photos)) {
$photos = [$photos];
}
if (!is_dir($this->photos_path)) {
mkdir($this->photos_path, 0777);
}
for ($i = 0; $i < count($photos); $i++) {
$photo = $photos[$i];
$name = sha1(date('YmdHis') . str_random(30));
$save_name = $name . '.' . $photo->getClientOriginalExtension();
$resize_name = $name . str_random(2) . '.' . $photo->getClientOriginalExtension();
Image::make($photo)
->resize(250, null, function ($constraints) {
$constraints->aspectRatio();
})
->save($this->photos_path . '/' . $resize_name);
$photo->move($this->photos_path, $save_name);
$upload = Upload::find($id);
$upload->filename = $save_name;
$upload->resized_name = $resize_name;
$upload->original_name = basename($photo->getClientOriginalName());
$upload->vehicle_id = $vehicle->id;
$upload->save();
}
and route is,
Route::post('myads/{id}', [
'uses' => '\App\Http\Controllers\VehicleController@update',
])->name('vehicles.edit');
but when I attach image and click update buttons it is not update image in uploads table. how can fix this problem?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire