rinvex / laravel-categories

Rinvex Categorizable is a polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.
MIT License
453 stars 68 forks source link

All scopes doesn't work with "string" primary keys #15

Closed mostafaznv closed 6 years ago

mostafaznv commented 6 years ago

Hi,

Thanks for this nice package. I need to cast all ID and primary keys to string because of client-side reasons. and I found an issue on this matter. all query scopes doesn't work with string.

example: Model::withCategories([1, 2])->get(); worked

Model::withCategories(["1", "2"])->get(); empty response

Omranic commented 6 years ago

Yes, this is intended behavior as we try to make this package flexible in accepting any kind of inputs, and then check data type & accordingly decide how to treat it, so if you're passing integers make sure to cast it first before passing to any of this package's methods.

mostafaznv commented 6 years ago

As i understand, we can't use this package with UUID primary keys?

Omranic commented 6 years ago

I didn't try it, but I guess you can do it by overriding the model and maybe the migration. The model is easily configurable through config options, so no core changes needed.

mostafaznv commented 6 years ago

ok, thanks I'll try it

giovannipds commented 4 years ago

Got a similar issue related, solved it this way:

$category_ids = $request->input('category_ids'); // ["1", "2"]
$category_ids = array_map('intval', $category_ids); // [1, 2]
$categorizable_model->syncCategories($category_ids);
Omranic commented 4 years ago

Thank you for your patience, this has been fixed in recent commit too https://github.com/rinvex/laravel-categories/commit/8ca17e72ed7849a9d38a5aecda954c3a81cc2938