Categorizable is a package provides an easy way to manage the model categories in Laravel.
Install the latest version using Composer.
1composer require pharaonic/laravel-categorizable2php artisan migrate
This is how you can create a new multilingual category.
This package depends on Translatable, Sluggable.
1use Pharaonic\Laravel\Categorizable\Models\Category;2 3$category = Category::create(['type' => 'products']); // type is nullable4$category->translateOrNew('en')->title = 'First Category'; // required5$category->translateOrNew('en')->description = 'Description Here'; // nullable6$category->save();
This is what you should to include in your model file.
1namespace App\Models; 2 3use Illuminate\Database\Eloquent\Model; 4use Pharaonic\Laravel\Categorizable\Traits\Categorizable; 5 6class Product extends Model 7{ 8 use Categorizable; 9 10 protected $fillable = ['title'];11}