Reputation: 55
I am trying to query for records using eloquent.
this works fine:
$xs = X::all()->where('y_id', 1);
return view('x', compact('xs'));
but when i try to pass a variable:
$xs = X::all()->where('y_id', $id);
return view('x', compact('xs'));
it returns empty array!
how can I do this query?
Upvotes: 2
Views: 736
Reputation: 950
The query should be
$xs = X::where('y_id', $id)->get();
all() returns all the records without any condition if you use a condition do a get() after all conditions queries
Upvotes: 1