A
A
Artur Bekerov2014-11-24 21:33:15
Laravel
Artur Bekerov, 2014-11-24 21:33:15

How correct is the following Eloquent/Laravel code?

There is a certain list which we receive from basis.
Let's call it a list of people.

protected function getPeoples($id) {
        $results = Peoples::all();
        return $results;
    }

Next, we need to get several elements that refer to one person:
protected function getCases($id) {
        $results = Cases::where('PeopleID', '=', $id)->get();
        return $results;
    }

And cases, in turn, also have several nested elements:
protected function getCases($id) {
        $results = Cases::where('PeopleID', '=', $id)->get();
        foreach ($results as $result) {
            $result->bills = Bills::where('CaseID', '=', $result->CaseID)->with('statuses')->get(array('BatchID'));
        }
        return $results;
    }

How true is the following and how to do with left join.
I sometimes find it easier to just use SQL than to convert the SQL to eloquent code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gladkovskiy, 2014-11-24
@krekerov

Try to use has-many-through links to avoid extra request for bills.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question