Blade Edit Form Validation for multiselect using Laravel 5 -


the following method in controller edit form.

public function edit($id){     $userlistedit = $this->getusers();     $modulesedit = $this->getmodules();     $editaccessarray = array(         'model'=>$this->accessmodel,         'select'=>array('access_id','access_loginid','access_modules'),         'where'=>array('access_id'=>$id)     );     $accessdetails = $this->select($editaccessarray);     $moduleslist = json_decode($accessdetails[0]['access_modules']);     return view('soa.useraccess.accessedit')->with('useraccessdetails',$accessdetails)->with('userlist',$userlistedit)->with('modules',$modulesedit)->with('moduleslist',$moduleslist); } 

following code update:

public function update($id,request $useraccesseditrequest){     $accessrules = array(         'modules'=>'required',     );     $accessmsgs = array(         'modules.required'=>'select modules'     );     $useraccesseditvalidator = validator::make($useraccesseditrequest->all(),$accessrules,$accessmsgs);     if($useraccesseditvalidator->fails()){         return redirect('useraccess/'.$id.'/edit')->witherrors($useraccesseditvalidator)->withinput();     }     else{         echo "<pre>";print_r($useraccesseditrequest->all());     } } 

i have issue while validating form. able populate multiselect pre selected values problem in case modules field required i.e., in case if modules field empty validation message should display empty multiselect, selected values. following code multiselect in blade view:

<div class="col-md-12" style="margin-top:2%;">     <label for="modules" class='control-label soalabelclass col-md-4'>modules</label>     <div class="col-md-8">         <select name="modules[]" class="form-control select2 select2class" multiple="multiple" data-placeholder="select modules" style="width:50%;">             @foreach($modules $module)                                                               <option value="{{$module['modules_key']}}"  {{ (collect(old('modules'))->contains($module['modules_key'])) ? 'selected':'' }} {{ (in_array($module['modules_key'],$moduleslist)) ? 'selected' : ''}}  >{{$module['modules_values']}}</option>             @endforeach         </select>     </div> </div> 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -