Pharaonic
Loading...

# categorize

You can use any of this ways to assign a category to the model.

1$product->categorize(1, 2); // Categories IDs
2$product->categorize([1, 2]); // Array of Categories IDs
3 
4$product->categorize(Category::all()); // Eloquent Collection of Categories
5 
6$product->categorize($category1, $category2); // Models
7$product->categorize([$category1, $category2]); // Array of Models

# decategorize

You can use any of this ways to detach a model from categories.

1$product->decategorize(1, 2); // Categories IDs
2$product->decategorize([1, 2]); // Array of Categories IDs
3 
4$product->decategorize(Category::all()); // Eloquent Collection of Categories
5 
6$product->decategorize($category1, $category2); // Models
7$product->decategorize([$category1, $category2]); // Array of Models

# syncCategories

You can use any of this ways to detach a model from all unnecessary categories and attach/keep it to all necessary categories.

1$product->syncCategories(1, 3); // Categories IDs
2$product->syncCategories([1, 3]); // Array of Categories IDs
3 
4$product->syncCategories(Category::all()); // Eloquent Collection of Categories
5 
6$product->syncCategories($category1, $category3); // Models
7$product->syncCategories([$category1, $category3]); // Array of Models