laravel - selected value tag of Form::model doesn't bind property from Model -


i'm learning laravel , have issue when trying bind property of model selected values of select tag. tried leave 3rd parameter null because believe form model binding automatically take care of doesn't work. here tried:

   {{$article->tag_list}} // show [1,3]      //it doesn't work     {!! form::select('tag_list[]', $tags, null , ['class' => 'form-control', 'multiple'] ) !!}     -------------      //it doesn't work     {!! form::select('tag_list[]', $tags, $article->tag_list  , ['class' => 'form-control', 'multiple'] ) !!}     -----------      //it works     {!! form::select('tag_list[]', $tags, [1,3] , ['class' => 'form-control', 'multiple'] ) !!} 

in model have gettaglistattribute() works fine.

public function gettaglistattribute(){     return $this->tags->lists('id'); } 

with text input, form works fine. btw, i'm using 5.2.1 version. missing here ?

i found missing piece. select function expects array gettaglistattribute() return collection object.

public function gettaglistattribute(){   return $this->tags->lists('id')->all(); } or can public function gettaglistattribute(){   return $this->tags->lists('id')->toarray(); } 

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 -