2

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?

1
  • 1
    add ->get(); at the end of the query. Commented Mar 2, 2016 at 5:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.