samedi 26 septembre 2020

Get/Sort a category of post from a location and its sub-locations Laravel

So I have a relationship between models; category, location, and post model. In the location table, there is a column called parent_id which stores the id of any location in that table, chosen to be the parent.

For Example: I can store a country as location and store a state to be under it, and also store a city under that state too;

United States
- New York
  - Buffalo, New York

But I want to be able to find a category in not just the location but also its sub-locations or the locations under it.

This code only gets me the category from one location, and not its sub-locations too

return $category->post()->where('status', '=', 'PUBLISHED')->where('location_id', '=', $location->id)->get();

I want to be able to check the category in its sub-locations too

Please help. Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire