About the Laravel: Get{xxxx}attribute problem

Source: Internet
Author: User
The problem is that the drop-down menu is not selected by default
There is a drop-down menu for select in the interface that modifies the content of the article:
( already on the head of the form, the corresponding $article model is bound)

    {!! Form::label('tag_list', 'Tags:') !!}    {!! Form::select('tag_list[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}

Also, the method of setting the collector in the article model:

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

In the interface, each option in select has the correct value, but it is not selected.
Then want to ask again, use laravel form of the Select, is not automatically go to correspond to gettaglistattribute this method?? The corresponding relationship is associated with the Name property of the select tag?

Add:

    1. The picker can get the corresponding article tag ID on the article List page.

    2. When editing an article, the other words of the article Geru (title, content) have corresponding content, model model binding is no problem

Reply content:

The problem is that the drop-down menu is not selected by default
There is a drop-down menu for select in the interface that modifies the content of the article:
( already in the form's head, the corresponding $article model is bound )

    {!! Form::label('tag_list', 'Tags:') !!}    {!! Form::select('tag_list[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}

Also, the method of setting the collector in the article model:

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

In the interface, each option in select has the correct value, but it is not selected.
Then want to ask again, use laravel form of the Select, is not automatically go to correspond to gettaglistattribute this method?? The corresponding relationship is associated with the Name property of the select tag?

Add:

    1. The picker can get the corresponding article tag ID on the article List page.

    2. When editing an article, the other words of the article Geru (title, content) have corresponding content, model model binding is no problem

You do this is possible, but also single-choice multi-selection of the general wording, the attributes can be one-to-many correspondence.

But you forget that the From header is also used from the output to the model form.

Laravel have any problems to communicate with me.

Theo, you add the->all () method to the back of the lists, the main point is to turn collection into an array here.

Lists in Laravel5 is the collection data structure, plus all after the array is taken out!

return $this->tags->lists (' id ')->all ();

has been said so detailed, can not solve and not to say.

Suppose you store the data variable called $data , then the name of the select and $data inside the key value to correspond, that $data is to store the tag key value called tag_list , should be so ~
If the key value is tag_id , change it to{!! Form::select('tag_id[]', $tags, null, ['class' => 'form-control', 'multiple']) !!}

You've been learning your video for help before @JellyBool.

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.