Closed zcwilt closed 4 years ago
you can handle it with type
column in categories table
Hi @mostafaznv,
I don't see any type
column in categories table when looking at the migration file.
Where did you get it ?
Hi @mostafaznv,
I don't see any
type
column in categories table when looking at the migration file. Where did you get it ?
I added it to migration before migrate.
You can do this with a Inner Join ;). I will paste the code tomorrow!
You can do this with a Inner Join ;). I will paste the code tomorrow!
Can you please paste the code? Thanks.
@joooseb any update on that code?
Honestly, I don't see any need for this in my opinion, as you can achieve the same results using the package as it is with the current structure, as one model, and that's using the polymorphic relations used already by default. Example on how to use it already documented here https://github.com/rinvex/laravel-categories#retrieve-all-models-attached-to-the-category
All what you need is the following code:
$category = app('rinvex.categories.category')->find(1);
$category->entries(\App\Models\Post::class);
That way you can retrieve categories related to products, news, or any unlimited number of models actually. Happy coding, and please feel free to re-open for further discussion 🙂
what happens when we need product categories and contact categories? should we have to keep them in the same table?
By default yes, you can create a root category for each, then put sub-categories inside as children.
what happens when we need product categories and contact categories? should we have to keep them in the same table?
For example, you have a category: Book
Then, Both Products
and Contact
can use this.
That way you can retrieve categories related to products or contact or ...
$category = app('rinvex.categories.category')->find(1);
$products = $category->entries(\App\Models\Product::class);
$contacts = $category->entries(\App\Models\Contact::class);
Currently code only allows for one category model In an admin type UI, I may want to display categories that relate to News, products, blog posts etc.
To achieve this each model needs to have an initial query that loads categories that relate to that model.
While the nestedSet code allows me to have multiple roots, given there is currently only one category model, there is no simple way to display these for each type
The proposal suggests extending the configuration settings from
to something like
To achieve this there needs to be only fairly minor changes to current code.
In the serviceProvider we need to iterate over the config settings
e.g.
and in the Categorizable Trait add this method
This method can be overriden in other categorizable models
e.g.
In a products model
In the Categorizable trait references to
config('rinvex.categories.models.category')
change toconfig('rinvex.categories.models.' . $this->getRinvexModelKey())
and references toapp('rinvex.categories.category')
change toapp('rinvex.categories.' . $this->getRinvexModelKey())