I want to retrieve all users data except one.for that i used the following query
$users=User::whereNotIn('name',['admin'])->pluck('id','name');
When i dd() the output I see all the users data except the one But when I send the query results in foreach()
loop in view page I see
Trying to get property of non-object
Error in view page.What’s the Error here? Can anyone suggest me please?
Here is the foreach loop i used in view page
@foreach($users as $user) <option value="{{$user->id}}">{{$user->name}}</option> @endforeach
Advertisement
Answer
pluck()
creates an array with [id => name]
structure, so change the code in assign_role.blade.php
to:
@foreach ($users as $id => $name) <option value="{{ $id }}">{{ $name }}</option> @endforeach
And pluck()
parameters to:
->pluck('name', 'id');