The problem is that the drop-down menu is not selected by default on the page for modifying the document content. There is a select drop-down menu: (the $ article model has been bound to the Form header) {code ...} in addition, in the Article model, set the method of the reader: {code ...} in the interface, select... the problem is that the drop-down menu is not selected by default.
On the document content modification page, a select drop-down menu exists:
(
The $ article model is bound to the Form header.)
{!! Form::label('tag_list', 'Tags:') !!} {!! Form::select('tag_list[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}
In addition, you can set the iterator in the Article model:
public function getTagListAttribute () { return $this->tags->lists('id'); }
On the interface, each option of select has a correct value, but is not selected.
Then I want to ask again, will the select statement of laravel Form automatically correspond to the getTagListAttribute method ?? Is the relationship associated with the name attribute of the select tag?
Add:
On the document list page, the reader can obtain the corresponding article tag id.
When editing an article, other fields of the article, such as the title and content, have corresponding content, so it is okay to bind the model.
Reply content:
The problem is that the drop-down menu is not selected by default.
On the document content modification page, a select drop-down menu exists:
(The $ article model is bound to the Form header.)
{!! Form::label('tag_list', 'Tags:') !!} {!! Form::select('tag_list[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}
In addition, you can set the iterator in the Article model:
public function getTagListAttribute () { return $this->tags->lists('id'); }
On the interface, each option of select has a correct value, but is not selected.
Then I want to ask again, will the select statement of laravel Form automatically correspond to the getTagListAttribute method ?? Is the relationship associated with the name attribute of the select tag?
Add:
On the document list page, the reader can obtain the corresponding article tag id.
When editing an article, other fields of the article, such as the title and content, have corresponding content, so it is okay to bind the model.
You can do this. It is also a general method of multiple choice, and the attributes can also be one-to-one.
However, you forget that the from header must be output in the form of a model.
Laravel can contact me if you have any questions.
You add the-> all () method after lists, which is mainly to convert the collection to an array.
In laravel5, lists obtains the collection data structure. After all is added, the array is obtained!
Return $ this-> tags-> lists ('id')-> all ();
If you have already said this in detail, you can't solve it any more.
Assume that the variable you store data is$data
, The select name must correspond to the key value in $ data, that is$data
The key value for storing tags istag_list
, It should be like this ~
If the key value istag_id
, You need to change it{!! Form::select('tag_id[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}
@ JellyBool your video for help