Use this code to define column with {type} type:

Column::{type}('{field name}')

Supported Types

Column Header

You can set column header label for each column type:

…->label('My Column Header')

Register Custom Column

You can register your own class as column:

Column::register('yesNo', \Acme\YesNoColumn::class)

Your column class must extend SleepingOwl\Admin\Columns\Column\BaseColumn (if you dont want to get value from instance by name) or SleepingOwl\Admin\Columns\Column\NamedColumn (in opposite case).

class YesNoColumn extends SleepingOwl\Admin\Columns\Column\NamedColumn
{

    public function render()
    {
        $params = [
            'value'  => $this->getValue($this->instance, $this->name()),
        ];
        return view('my-view', $params);
    }

}

Usage in model configuration

$display->columns([
    Column::yesNo(),
]);

Restrict Column Sort

Column::string('my_field')->orderable(false)

Column Appendants

Filter Appendant

Column::filter('{filter_alias}')->model('App\MyModel')->value('{field to grab filter value from}')

It will add filter button to every column cell, that links to model display filter. You can omit model() definition if you want to use the current model.

Example:

Column::string('category.title')->label('Category')->append(
    Column::filter('category_id')
)

Url Appendant

Column::url('{field to grab url from}')

It will add button to every column cell, that links to provided in model field url.

Example:

Column::string('url', 'Url')->append(
    Column::url('full_url')
)

String

Cell content will be simple field value from your model or one of related models.

Column::string('{field name}')

Field Name

Field name can be one of the following:

  • Field from your model (from database or using mutators).

    Column::string('title')
    Column::string('url')
  • Field from your model relations

    Column::string('category.title') // category() creates belongs-to relation
    Column::string('city.state.title') // you can use nested relations

Lists

Cell content will be list of related models. Used in many-to-many relations.

Column::lists('categories.title')

It will display list of all category titles associated with current entity.

categories() must create belongs-to-many relation in this case.


Count

Cell content will be count of related models. Used in has-many relations.

Column::count('images')
Column::count('images')->append(
    Column::filter('school_id')->model('App\SchoolImage')
)

images() must create has-many relation in this case.


Image

Cell content will be an image thumbnail.

Column::image('photo')

photo must be return full url to the image or path related from your project public directory.

Image columns can`t be sortable.


Datetime

Cell content will be date or time value.

Column::datetime('{field}')

Format Date and Time

Default format is defined in config datetimeFormat property. You can override it with format($format) method.

Column::datetime('created_at')->format('d.m.Y H:i:s')
Column::datetime('created_at')->format('m/d/Y g:i')

Order

Cell content will be up and down arrows.

Column::order()

Your model must include use SleepingOwl\Admin\Traits\OrderableModel; trait in order to use this column type. Your model must contain integer field that represents order of entities. You must implement getOrderField() method in your model and return this field name:

public function getOrderField()
{
    return 'order';
}

Example

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    use SleepingOwl\Admin\Traits\OrderableModel;

    public function getOrderField()
    {
        return 'order';
    }
}

Action

Cell content will be button with custom action.

Column::action('{name}')

Button Styling

You can specify icon class to use (from FontAwesome):

Column::action('show')->icon('fa-globe')

2 styles are available: short and long

 # This will create button without label, only with icon. Label will popup on hover.
Column::action('show')->label('Label')->icon('fa-globe')->style('short')

 # This will create button with icon and label
Column::action('show')->label('Label')->icon('fa-globe')->style('long')

Defaults: default style is long without icon.

Button Target

You can specify target for button:

Column::action('show')->label('Column Label')->value('Button Text')->url('http://test.com/:id')->target('_blank')

URL Usage

You can specify url for button, :id will be replaced with the clicked row id:

Column::action('show')->label('Label')->url('http://test.com/:id')

or you can provide callback to generate url:

Column::action('show')->label('Label')->url(function ($instance)
{
    return URL::route('my-route', [$instance->id]);
})

Custom Actions Usage

Use ->callback() method to set custom action:

Column::action('show')->label('Label')->callback(function ($instance)
{
    # Any code you want
})

Checkbox

Checkbox column is used to perform bulk actions.

Column::checkbox()

For details see bulk actions.


Custom

This column type uses your callback to get cell value.

Column::custom()->label('Published')->callback(function ($instance)
{
    return $instance->published ? '✓' : '-';
}),