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
$users = User::where('id', '!=', Auth::id())->get();
this one except current login user..you can set admin id...in such field.. or you can use this also..
$users = User::all()->except(Auth::id());
both are work!!
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With