I am trying to make a chained Eloquent request to Laravel and bring users from the user table with a conditional, namely, if they belong to a certain house. I'm struggling a bit to find a way to make this work. Can anybody help me?
This is my controller method:
public function create(){
if(Auth::user()->role->id == 1){
$house = House::findOrFail(Auth::user()->house->id);
$jobs = Job::pluck('name', 'id')->all();
$categories = Category::pluck('name', 'id')->all();
$users = User::pluck('name', 'id')->where('house_id', $house)->get();
return view('admin.tasks.create', compact('jobs', 'categories', 'users'));
}else{
return redirect('home');
}
}
The error was passed to me when using get ():
Type error: Too few arguments to function Illuminate\Support\Collection::get(), 0 passed in /Applications/MAMP/htdocs/Housing_around/app/Http/Controllers/AdminTasksController.php on line 55 and at least 1 expected
And all()at the end , they thought nothing returned to me in the returned array
Does anyone have a clue on how to proceed?
Thank!
source
share