Firstly i made laravel relations in models and foreign key. My foreign key is user_id.
This is part of my view witch generate error:
<select class="form-controll" name="user_id"> @foreach($users as $user) <option value="{{$user->id}}">{{$user->name}}</option> @endforeach </select>
This is controller method for this view
<?php namespace AppHttpControllers; use KyslikColumnSortableSortable; use AppProduct; use IlluminateHttpRequest; use AppUser; ... public function edit(Product $product) { $user = User::all('name','id'); return view('products.edit',compact('product', 'user')); } ...
Advertisement
Answer
You are using ‘user’ not ‘users’ in your compact function. Also your variable is defined as $user
not $users
. It should be like this:
public function edit(Product $product) { $users = User::all('name','id'); return view('products.edit',compact('product', 'users')); }