function getSearch($query) { $productions = Production::search($query); $persons = Person::search($query); foreach ($persons as $person) { $pros = $person->productions()->orderBy(Production::ATTR_STATE, "DESC")->get(); foreach ($pros as $pr) { $productions[] = $pr; } } $productions = Production::sortByState($productions); return view("frontend/contents/gen/search")->with("productions", $productions)->with("persons", $persons)->with("query", $query); }