Skip to content

Collection Lists configuration

The configureOzuCollectionList() allows you to configure the list used to display your collections in the CMS section of Ozu dashboard.

php
use Code16\OzuClient\Eloquent\IsOzuModel;
use Code16\OzuClient\OzuCms\OzuCollectionListConfig;

class Project extends Model
{
    use IsOzuModel;

    public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
    {
        return $config
            ->addColumn(OzuColumn::makeImage('cover', 1))
            ->addColumn(OzuColumn::makeText('title', 4)->setLabel('Title'))
            ->addColumn(OzuColumn::makeText('place', 3)->setLabel('Place'))
            ->addColumn(OzuColumn::makeText('year', 3)->setLabel('Year'))
            ->setIsSearchable()
            ->setIsReorderable();
    }
    
    // ...
}

Available methods of OzuCollectionListConfig

The configureOzuCollectionList method receives an OzuCollectionListConfig instance which provides several methods to configure the list behavior and its columns.

General Configuration

  • setIsReorderable(bool $reorderable = true): Enable drag-and-drop reordering for the list items (default: false)
  • setIsSearchable(bool $searchable = true): Add a search bar to the list (default: false)
  • setIsPaginated(bool $paginated = true): Enable pagination for the list (default: false)
php
class Project extends Model
{
    use IsOzuModel;
    
    public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
    {
        return $config
            ->setIsReorderable(false)
            ->setIsSearchable()
            ->setIsPaginated();
    }

    // ...
}

Handling displayed columns

You can add columns to your list using the addColumn(OzuColumn $column) method. Columns are created using static factory methods on the OzuColumn class.

php
use Code16\OzuClient\OzuCms\List\OzuColumn;

class Project extends Model
{
    use IsOzuModel;

    public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
    {
        return $config
            ->addColumn(OzuColumn::makeText('title')->setLabel('Title'))
            ->addColumn(OzuColumn::makeDate('created_at')->setLabel('Created at'));
    }

    // ...
}

Column Types

All columns are created using static factory methods on the OzuColumn class. Most methods take a key (matching the attribute name) and an optional size (percentage).

Common Column Methods

All columns share these methods:

  • setLabel(string $label): Set the column header label.
  • setDefaultSort(string $direction = 'asc'): Set this column as the default sort for the list.

Text Column (OzuColumn::makeText)

Displays simple text content.

php
OzuColumn::makeText('title')->setLabel('Title')

Date Column (OzuColumn::makeDate)

Displays a formatted date.

php
OzuColumn::makeDate('published_at')->setLabel('Published')

Image Column (OzuColumn::makeImage)

Displays a small thumbnail of the image.

php
OzuColumn::makeImage('cover')->setLabel('Cover')

Check Column (OzuColumn::makeCheck)

Displays a boolean value as a checkmark icon.

php
OzuColumn::makeCheck('is_featured')->setLabel('Featured')

Filters

BelongsTo Filter

If your collection has a BelongsTo relationship toward another Ozu collection, you can add a filter to the list:

  • declareBelongsToFilter(string $ozuModelClass, string $label, bool $required = true)
php
class Project extends Model
{
    use IsOzuModel;

    public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
    {
        return $config
            ->declareBelongsToFilter(Category::class, 'Category');
    }
    
    // ...
}