0

in laravel i have ProdoctController and CategoryController, im passing the category data with this function:

public function view(){
  $category = Category::all();
  return view('admin.product.main',['category'=>$category]);
}

its working with normal mode in laravel:

<select>
 @foreach(category as categories)
   <option value='{{category->id}}">{{category->name}}</option>
 @endforeach
</select>

but in vue js i have a categories:[] in data, and i want to use this:

<select v-model="ProductCategory">
<option v-for="category in categories" :value="categories.id">categories.name</option>
</select>

how can i pass the data in categories array?

1 Answer 1

1

You can do something like this:

<script type="text/javascript">
    window.data = {!! json_encode([
        'categories' => $categories,
    ]) !!};
</script>

<select v-model="ProductCategory">
    <option v-for="category in window.data.categories" :value="category.id">category.name</option>
</select>

First part gets you the categories onto the view in the JavaScript and then Vue will have access to them. I think you should fix your category/categories variables, if this is a real code you've been using them not correctly, e.g. when you have a collection of many and when you have only one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.