About laravel's get: get {xxxx} Attribute

Source: Internet
Author: User
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:

  1. On the document list page, the reader can obtain the corresponding article tag id.

  2. 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:

  1. On the document list page, the reader can obtain the corresponding article tag id.

  2. 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$dataThe 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.