Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
if (Input::has('category')) {
    return Category::where('id', '=', Input::get('category'))->with('component', 'component.filter', 'component.codes')->get();
}
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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();
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.