laravel - File input label Blade -
i have form file input field, created label input , made input display none. , whenever upload pictures automatically submits form. problem return wrong id link if submit this, if have normal submit buttons works.
@foreach($wedstrijden $wedstrijd) <a class="verslag-manager-button" data-toggle="modal" data-target="#verslagmodal{{ $wedstrijd->id }}" href=""> <p>verslag </p> </a> --modal #verslagmodal{{ $wedstrijd->id }} <form action="/manager/fotos/upload/{{ $wedstrijd->id }}" class="upload" method="post" enctype="multipart/form-data"> <label class="btn btn-default btn-success" for="my-file-selector"> <input onchange="this.form.submit()" id="my-file-selector" multiple name="sourceimage[]" type="file" style="display:none;"> upload foto </label> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <input style="display: none" type="submit" value="upload image" name="submitbtn"> </form> --modal @endoforeach in route file have following route
route::post('manager/fotos/upload/{id}', 'managercontroller@postfotoupload'); but in controller returns latest id.
if inspect code in browser form url shows /manager/fotos/upload/16 if dump $id in controller return 17.
public function postfotoupload($id, request $request) { foreach($request->file('sourceimage') $foto) { $file = $foto; $destinationpath = 'img/' . $id . '/'; $filename = $file->getclientoriginalname(); $file->move($destinationpath, $filename); $foto = new foto(); $foto->wedstrijd_id = $id; $foto->foto = $filename; $foto->save(); } session::flash('upload', true); return redirect::to('/manager'); }
Comments
Post a Comment