laravel-nestedset icon indicating copy to clipboard operation
laravel-nestedset copied to clipboard

Handling of dynamic descendatsOf()

Open ronssij opened this issue 4 years ago • 0 comments

[
    {
      	"id": 1,
        "name": "Video",
        "children": [
            {
              	"id": 2,
                "name": "Workouts",
                "children": [
                    {
                      "id": 3,
                      "name": "How To's" 
                    },
                    { 
                      "id": 4,
                      "name": "Live Workouts"
                    },
                    { 
                      "id": 5,
                      "name": "Myth Busting"
                    }
                ]
            }
        ]

    }
]

I don't know if handling this scenario is possible in this package using spatie eloquent query. It is possible to attach to a model an ids of [2, 4, 5] but what happens is descendantsOf() only allow one id.

AllowedFilter::callback('category', function ($query, $category) {
  $query->withAnyCategories($category)->orWhere(function ($query) use ($category) {
      $categories = Category::descendantsOf($category);

      return $query->withAnyCategories($categories);
  });
}),

ronssij avatar Dec 07 '20 05:12 ronssij