php - In Laravel 5 error in array validation with Form Request? -


the part of form (the field text array)[1]:

<div id="cp1">     <div class="form-group">         {!! form::text('names[]',null,['class'=>'form-control', 'maxlength'=>'30', 'placeholder'=>'name']) !!}     </div>     <div class="form-group">         {!! form::text('contents[]',null,['class'=>'form-control', 'maxlength'=>'30', 'placeholder'=>'content']) !!}     </div> </div> 

when send form, validation fails with: htmlentities() expects parameter 1 string, array given (view: /applications/mamp/htdocs/telovendogdl/resources/views/ads/new.blade.php)

this rules in form request:

return ['title' => 'required|min:8|max:100',             'description' => 'required|min:10|max:1100',             'price' => 'required|integer|max:15',             'city_name'=> 'required|max:70',             'category_id' => 'required|integer',             'delivery'=> 'max:70',         ]; 

this function in controller:[2]

public function newadstore(storenewadrequest $request)     {         $newad = new ad;         $newad->user_id = \auth::user()->id;         $newad->active = 0;         $newad->city_name = $request->input('city_name');         $newad->category_id = $request->input('category_id');         $newad->fill($request->all());         $newad->save(); } 

but fails when send array fields form [1], when delete fields works? happen that[2]?

i don't have clear vision of code gonna try debug code ... first need add rule storenewadrequest handle array instead of string names[] , contents[] :

public function rules() {   $rules = [     'field2' => 'required|...',     'field3' => 'required|...',      ....    ];    foreach($this->request->get('names') $key => $val)   {     $rules['names.'.$key] = 'required|max:100';   }    return $rules; } 

make sure have right fillable params in model

note: problem maybe occurred @ stage

$newad->fill($request->all()) 

you trying fill array of names[] & contents[] instead of strings ..


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -