Categories

Enso comes with a default Category system.

Relationships

You can set up a relationship with Categories by applying one of two provided traits to your model.

use Yadda\Enso\Categories\Traits\BelongsToCategories;

// or

use Yadda\Enso\Categories\Traits\BelongsToManyCategories;

Applying Relationship in the Admin Area

To be able to apply categories to other Cruds in the admin area, you will need to add the appropriate fields to those Cruds.

For single category:

use Yadda\Enso\Categories\Models\Category;
use Yadda\Enso\Crud\Forms\Fields\BelongsToField;

// ...

$section->addField(
  BelongsToField::make('category')
      ->useAjax(route('admin.categories.index'), Category::class),
);

or for multiple categories:

use Yadda\Enso\Categories\Models\Category;
use Yadda\Enso\Crud\Forms\Fields\BelongsToManyField;

// ...

$section->addField(
  BelongsToManyField::make('categories')
      ->useAjax(route('admin.categories.index'), Category::class),
);

JSON Routes

You can quickly add simple JSON routes for your categories

EnsoCategories::routes('json/categories', EnsoCrud::controllerClass('category'), 'json.categories');