Get value of found array index

Posted 3 months ago by axtg


This may be a basic Javascript question, but I am trying to achieve the following...

  1. I have a Laravel Model that holds all attributes $attributes = Attribute::get(); that can be linked with properties (many to many; attributes_properties)

  2. I have a Laravel loaded array with objects that hold previously specified properties and with that the value of the property e.g. [{'id' => 1, 'value' => 'first'}, {'id' => 2, 'value' => 'second'}]. Passed as prop (selectedAttributes) to Vue.

The id in the Laravel model (1) equals the id listed in (2)

I am listing all attributes on a page via Vue (<div v-for="(attribute, index) in attributes">

Now I want to prefill the value for those attributes that have been filled before. Which theoretically means...

<div v-for="(attribute, index) in attributes">
    <input :value="[selectedAttributes.includes( ? selectedAttributes.value : '']">

But that obviously doesn't work (because selectedAttributes is missing an index).

Any pointers, as always, are welcome.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.