if (Input::has('category')) {
return Category::where('id', '=', Input::get('category'))->with('component', 'component.filter', 'component.codes')->get();
}
This kind of works. I "kind of" because it returns the a Category array that contains all the Component objects, rather than returning the array of Components I was aiming for, like the one returned with a simple:
$query = Component::with(["filter", "codes", "categories"]);
Thanks a lot though, it's a great start.
You can put a closure in the with
method.
$category = Input::get('category');
$query = Component::with(['categories' => function($query) use ($category) {
return $query->where('id', '=', $category);
}])->with(['filter', 'codes'])->get();
Thanks man, I already changed my angular code to match your first solution though, so it won't be necessary. I'll accept it as the solution anyway since people another person with the same problem might find it useful (as I will if I find myself in the same situation sometime).
Edit: I stupidly clicked "Mark as solution" on my own comment, proceeded to delete it to see if that option came back, but it doesn't. Sorry about that.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community