Skip to content

Commit

Permalink
Fix attaching categories by their IDs where IDs are passed mistakenly…
Browse files Browse the repository at this point in the history
… as strings in some cases! (Fixes #17 #34)
  • Loading branch information
Omranic committed Jun 12, 2020
1 parent c25d97d commit 8ca17e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Traits/Categorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ protected function prepareCategoryIds($categories): array
$categories = $categories->toArray();
}

// Find categories by slug, and get their IDs
// Find categories by their ids
if (is_numeric($categories) || (is_array($categories) && is_numeric(Arr::first($categories)))) {
return (array) $categories;
}

// Find categories by their slugs
if (is_string($categories) || (is_array($categories) && is_string(Arr::first($categories)))) {
$categories = app('rinvex.categories.category')->whereIn('slug', (array) $categories)->get()->pluck('id');
}
Expand Down

0 comments on commit 8ca17e7

Please sign in to comment.