The Route is Route::resource('/admin/post', 'postController');
in controller the code is
public function index()
{
$s = Singer::where('id','<',5)->get()->name;
return view("admin.new-post", ['s'=>$s]);
}
And the view is
<select class="form-control select2 select2-hidden-accessible" multiple="" data-placeholder="Select a State" style="width: 100%;" tabindex="-1" aria-hidden="true">
<?php foreach ($s as $ss){
echo '<option>'. $ss .'</option>';
}?>
</select>
I want to list down all the names of singers from data base in select. And the problem is that when I get a single value using first()
in query instead of get()
it returns single value correctly widhout any error. but when I use get()
and in view use foreach
loop to get all singers then it gives this error. Undefined property: Illuminate\Database\Eloquent\Collection::$name
. I have reviewed code many times but could not understand that what the error is. while there is no problem to get a single name.. please provide me some solution.