I need to select the id and name field, pass the collection to the view and iterate over it to generate options for a select. However, I am getting the following error:
Trying to get property of non-object (View: ../resources/views/layouts/app.blade.php) (View: ../resources/views/layouts/app.blade.php)
Controller
public function index()
{
$propertyTypes = PropertyType::pluck('name', 'id');
return view('home', compact('propertyTypes'));
}
View
@foreach($propertyTypes as $propertyType)
<option value="{{ $propertyType->id }}">
{{ $propertyType->name }}
</option>
@endforeach
Table
ID Name
1 Detached
2 Semi-detached
3 Terraced
4 Flat
5 Bungalow
6 Land
7 Park Home