Jul 22, 2017
0
Level 1
Laravel 5.4 upload images with specific id
Hi all,
I have form to upload images and save image in db with specific id. How can i change image with specific id???
Controler for upload image
public function upload(Request $request)
{
$last_row = DB::table('cars_models')->latest()->first();
$destinationPath = 'images/'.$last_row->id; // upload path
$insertedId =$last_row->id;
$input['image'] = time().'.'.$request->image-
>getClientOriginalExtension();
$request->image->move(public_path($destinationPath), $input['image']);
$input['id_cars'] = $last_row->id;
ImageGallery::create($input);
$images = ImageGallery::get();
return view('image-gallery',compact('images','insertedId'));
}
This controller I use to import image and id in database.
View:
<form action="{{ url('image-gallery') }}" class="form-image-upload" method="POST"
enctype="multipart/form-data">
<div class="row">
<div class='list-group gallery'>
@if($images->count())
@foreach($images as $image)
@if($image->id_cars==$insertedId)
<div class='col-sm-4 col-xs-6 col-md-3 col-lg-3'>
<a class="thumbnail fancybox" rel="ligthbox" href="images/{{$image->id_cars}}/{{ $image->image }}">
<img class="img-responsive" alt="" src="images/{{$image->id_cars}}/{{ $image->image }}" />
</a>
<form action="{{ url('image-gallery',$image->id) }}" method="POST">
<input type="hidden" name="_method" value="delete">
{!! csrf_field() !!}
<button type="submit" class="close-icon btn btn-danger"><i class="glyphicon glyphicon-remove"></i></button>
</form>
</div> <!-- col-6 / end -->
@endif
@endforeach
@endif
</div> <!-- list-group / end -->
and this my view .
Route is:
Route::get('image-gallery', 'ImageGalleryController@index');
Route::post('image-gallery', 'ImageGalleryController@upload');
Route::delete('image-gallery/{id}', 'ImageGalleryController@destroy');
How can I change my controller or view to make to edit image (for specific id to delete and upload new image). I use laravel 5.4.
Any ide?
Please or to participate in this conversation.