Builders


Introduction

Builders are classes that require minimal configuration and provide complex structures. For example a TableBuilder will build a Table object as well as it's various components like Columns, Buttons, Actions, and Filters among others.

Builders use smart automation and guessing to try and configure themselves as much as possible based on surrounding classes, streams information, and defaults. You can then define more or less configuration as needed to override behavior and meet your project's specific requirements.

Here is a slightly more sophisticated example (note the custome filter query) of a table builder:

<?php namespace Anomaly\PostsModule\Post\Table;

use Anomaly\PostsModule\Post\Table\Filter\StatusFilterQuery;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;

class PostTableBuilder extends TableBuilder
{

    /**
     * The table filters.
     *
     * @var array
     */
    protected $filters = [
        'search' => [
            'fields' => [
                'tags',
                'title',
                'summary',
                'meta_title',
                'meta_keywords',
                'meta_description',
            ],
        ],
        'author',
        'category',
        'status' => [
            'filter'  => 'select',
            'query'   => StatusFilterQuery::class,
            'options' => [
                'live'      => 'anomaly.module.posts::field.status.option.live',
                'draft'     => 'anomaly.module.posts::field.status.option.draft',
                'scheduled' => 'anomaly.module.posts::field.status.option.scheduled',
            ],
        ],
    ];

    /**
     * The table columns.
     *
     * @var array
     */
    protected $columns = [
        'title',
        'author',
        'category',
        'status' => [
            'heading' => 'anomaly.module.posts::message.status',
            'value'   => 'entry.status_label',
        ],
    ];

    /**
     * The tree buttons.
     *
     * @var array
     */
    protected $buttons = [
        'edit',
        'view' => [
            'target' => '_blank',
        ],
    ];

    /**
     * The table actions.
     *
     * @var array
     */
    protected $actions = [
        'delete',
    ];

    /**
     * The table options.
     *
     * @var array
     */
    protected $options = [
        'order_by' => [
            'publish_at' => 'DESC',
        ],
    ];
}

You can then use method injection to include this table in your controller and display it:

public function index(PostTableBuilder $table)
{
    return $table->render();
}

Which produces a table of entries with powerful features:

{{ img('local://help_center/posts-table-example.png').width('100%')|raw }}