php - Can not update the data -


route

route::resource('/mediafile', 'mediacontroller'); 

mediacontroller

public function update(request $request, $id) {     $media = media::findorfail($id);     if($request->hasfile('userfile')) {         $image = $request->file('userfile');         $filename = $image->getclientoriginalname();           image::make($image)->resize(300, 300)->save(public_path('media/' . $filename));         $media->mediapath = $filename;         $media->medianame = $filename;         $media->description = $request->description ? $request->description : '';         $media->save();     }      return response()->json($media);  } 

view

<form class="form-horizontal" id="media-form" enctype="multipart/form-data">     {{ csrf_field() }}         <div class="form-group">             <div class="col-xs-6 col-sm-6 col-md-6">                 <label for="medianame">nama media</label>               @if($edit)               <input type="text" id="medianame" class="form-control" name="medianame" value="{{$mediaedit != null ? $mediaedit->medianame : ''}}">               @else                 <input type="text" id="medianame" class="form-control" name="medianame">               @endif                 @if ($errors->has('medianame'))                 <span class="help-block">                     <strong>{{ $errors->first('medianame') }}</strong>                 </span>                 @endif             </div>         </div>          <div class="form-group">             <div class="col-xs-6 col-sm-6 col-md-6">                 <label for="description">description</label>             @if($edit)             <textarea class="form-control" name="description" style="height: 200px">{{$mediaedit->description}}</textarea>                 @else             <textarea class="form-control" name="description" style="height: 200px"></textarea>             @endif                 @if ($errors->has('description'))                 <span class="help-block">                     <strong>{{ $errors->first('description') }}</strong>                 </span>                 @endif             </div>         </div>          <div class="form-group">             <div class="col-xs-6 col-sm-6 col-md-6">                 <label for="gambar">gambar</label>             @if($edit)             <img src="{{ asset('media/' . $mediaedit->mediapath) }}" style="height: 150px;margin-left: 10px">             <textarea readonly="" class="select valid" style="height:30px; width: 100%; margin-top: 10px">{{ asset('media/' . $mediaedit->mediapath) }}</textarea>                 @endif             <input type="file" name="userfile">             </div>         </div>          <input type="hidden" name="_token" value="{{ csrf_token() }}"></input>         <input type="hidden" name="_method" value="post"></input>         <button type="submit" class="btn btn-info">submit</button>      </form> 

ajax

$('#media-form').submit(function(){ var formdata = new formdata(this); swal({   title: 'are sure?',    type: 'info',   showcancelbutton: true,   confirmbuttoncolor: "#dd6b55",   confirmbuttontext: "confirm!",   closeonconfirm: false,   closeoncancel: false   },     //function     function(isconfirm){       if(isconfirm){         $.ajaxsetup({             headers: {                 'x-csrf-token': $('meta[name="csrf-token"]').attr('content')             }         });         $.ajax({           type: "<?php echo $actionmethod; ?>",           url: "<?php echo $actionurl; ?>",           data: formdata,           datatype: 'json',           processdata: false, // don't process files             contenttype: false, // set content type false jquery tell server query string request         })         .done(function(data){           if(data.id){               swal({                 title: "saved!",                 text: "your category has been saved.",                 type: "success"}, function(){                   window.location.href = "<?php echo url('mediafile'); ?>";               });             }else{               swal("try again");             }             console.log(data);         })         .error(function(data){             swal("cancelled", "please fill data first.");             console.log('error:', data);         });       } else{         swal("cancelled");       }     //end function }); return false; }); 

i put medianame, description, , userfile

enter image description here

when clicked submit, got data this

enter image description here

i can not update data, when try update them, data have not changed. don't know why, think did not wrong in code.. please me solve if know answer

<form  name="itemgroupform" action="{{url::to('edititem',$items[0]->id)}}"   id="itemgroup" data-parsley-validate="" method="post"  onsubmit="return submitformitemgroup();">       function submitformitemgroup() {   var form_data = new formdata(document.getelementbyid("itemgroup"));   form_data.append("label", "webupload");   $.ajax({       url: "{{url::to('edititem',$items[0]->id)}}}",       type: "post",       data: form_data,       processdata: false,  // tell jquery not process data       contenttype: false   // tell jquery not set contenttype   }). 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -