I am trying to list all entries which fall under a where condition. If I do the following, I get all the entries returned
$users = User::lists('userName', 'id');
However, I am looking to return only the users who have a department id of 3. So I am doing
$users = User::lists('userName', 'id')->where('departmentId', 3);
However, this returns an empty result set. In my database, I do have users with this department id.
How can I get the lists statement working?
Just a note, the following returns the result I need
$users = User::select('userName', 'id')->where('departmentId', 3)->get();
However, in my edit form, because I have this
!! Form::select('csManager', $users, Input::old('users'), ['class' => 'csManager']) !!}
The old input is not selected and the data is showing up as an array. I know the way to fix this is to do my select like this
<select class="csManager" name="csManager">
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->userName }}</option>
@endforeach
</select>
But then I am not sure how to display the old user within the above select.
Any help appreciated.
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire