© 2024 Jarboe
1.*

Installation

Add package to your composer.json:

copy
composer require yaro/jarboe

Follow installer steps:

copy
php artisan jarboe:install

Add command to composer.json for automatic assets update:

copy
"post-update-cmd": [
    "php artisan vendor:publish --provider=\"Yaro\\Jarboe\\ServiceProvider\" --tag=\"public\" --force"
],

Quick Start

Lets make some basic crud.

Prepare our database

Create migration file

copy
php artisan make:migration create_posts_table

And update it’s up method

copy
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->text('content');
        $table->boolean('is_published');
        $table->timestamps();
    });
}

Run migrations

copy
php artisan migrate

Create model

copy
php artisan make:model Post

Specify fillables and casting

copy
class Post extends Model
{
    protected $fillable = [
        'title',
        'content',
        'is_published',
    ];
    protected $casts = [
        'is_published' => 'boolean',
    ];
}

Create controller and define routes

copy
php artisan make:controller PostsController

Then extend new controller class from AbstractTableController and declare init method

copy
use Yaro\Jarboe\Http\Controllers\AbstractTableController;

class PostsController extends AbstractTableController
{
    protected function init()
    {
        //
    }
}

Now we’ll config crud. Just tell what model it should use and specify fields

copy
use Yaro\Jarboe\Table\Fields\Checkbox;
use Yaro\Jarboe\Table\Fields\Text;
use Yaro\Jarboe\Table\Fields\Wysiwyg;
//

protected function init()
{
    $this->setModel(Post::class);

    $this->addFields([
        Text::make('title'),
        Wysiwyg::make('content'),
        Checkbox::make('is_published'),
    ]);
}

Add to your routes file

copy
Route::group(Jarboe::routeGroupOptions(), function () {
    Jarboe::crud('posts', 'PostsController');
});

Update navigation menu

Copy navigation view to your local views folder, e.g. for default configuration:

cp vendor/yaro/jarboe/src/resources/views/inc/navigation.blade.php resources/views/vendor/jarboe/inc/navigation.blade.php

And add url of your newly created route to copied navigation view

copy
<li>
    <a href="https://jarboe.app/admin/posts">
        <i class="fa fa-lg fa-fw fa-newspaper-o"></i>
        <span class="menu-item-parent">Posts</span>
    </a>
</li>

Create admin user and authorize

Navigate to http://localhost/admin/register and register account, then login with your credentials at http://localhost/admin/login. After that open your posts route http://localhost/admin/posts

FAQ

Begin typing your question. If we don't have an answer for it in our FAQ, please leave us a message on our contact page.

  • How can I move admin panel on subdomain?

    1. set subdomain_panel_enabled to true in /app/config/jarboe/admin_panel.php.
    2. check your SESSION_DOMAIN in .env file (for Laravel version >=5.4, or domain in the sessions.php config file), it's value should be like .example.com - pay attention to dot at the beginning.
  • How to redefine table (list/create/edit) views?

    Views can be specified as attributes of table controller in $viewCrudList, $viewCrudCreate, $viewCrudEdit.
    copy
    class PostsController extends AbstractTableController
    {
        protected $viewCrudCreate = 'my_crud_create_view';
        //
    }
  • How to add locales switcher in admin panel?

    You can define locales list and current locale in jarboe/locales.php configuration files.
  • How to change auth guard for admin panel?

    Add new guard and provider in config/auth.php:
    copy
    'guards' => [
        //
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    
    ],
    
    //
    
    'providers' => [
       //
        'admins' => [
            'driver' => 'eloquent',
            'model' => \Yaro\Jarboe\Models\Admin::class,
        ],
    ],
    Specify newly created guard in config/jarboe/admin_panel.php configuration file at auth_guard key. That's it!

CRUD Table

Methods available in init method

Set class name for crud. Mandatory.

setModel(string $modelClass)

$modelClass - class name of model.

 

copy
$this->setModel(Post::class);

Add clauses to model instance.

filter(Closure $callback)

$callback - closure that takes one parameter $model.

 

copy
$this->filter(function($model) {
    $model->where('is_active', true);
});

Set how rows should be ordered.

order(string $column [, string $direction = 'asc'])

$column - model field by which model query should add orderBy clause.
$direction - direction for orderBy clause, supports asc and desc.

 

copy
$this->order('id', 'desc');

Add pagination to crud table.

paginate(int|array $perPage)

$perPage - pagination value; pass array of integers for adding per page select at the bottom of table.

 

copy
$this->paginate(25);
copy
$this->paginate([10, 20, 50, 100]);

Add new field object.

addField(AbstractField $field)

$field - field object.

 

copy
$this->addField(
    Text::make('title')
);

Add multiple field objects.

addFields(array $fields)

$fields - array of fields objects.

 

copy
$this->addFields([
    Text::make('title'),
    Markdown::make('content'),
]);

Add new tab and set fields to it.

addTab(string $title, array $fields)

$title- tab title.
$fields - array of fields objects.

 

copy
$this->addTab('Meta', [
    Text::make('meta_title'),
    Text::make('meta_description'),
]);

Set field as column in crud table.

addColumn(string $column)

$column- field name.

 

copy
$this->addColumn('title');

Set multiple columns.

addColumns(array $columns)

$columns- array of field names.

 

copy
$this->addColumns([
    'meta_title',
    'meta_description',
]);
copy
$this->addColumns([
    Text::make('id'),
    'title',
    'price',
]);

Set locales for all translatable fields in table.

locales(array $locales)

$locales - array of supported locales.

 

copy
$this->locales([
        'en' => 'English',
        'de' => 'Deutsch',
        'jp' => '日本人',
    ]);
copy
$this->locales([
        'en',
        'de',
        'jp',
    ]);

Add checkbox on the left side of each row for mass selection.

enableBatchCheckboxes(bool $enabled = true)

$enabled - enable/disable checkboxes.

 

copy
$this->enableBatchCheckboxes();

Allows to reorder table rows.

sortable(string $field)

$field - name of weight field for sorting.

 

copy
$this->sortable('sort_weight');

Enable soft deletes for table. Actions for restore and force delete will be shown.

softDeletes(bool $enabled = true)

$enabled - enable/disable soft deletes.

 

copy
$this->softDeletes();

Methods available in crud controller

Method that called before init(). For specifying default settings.

beforeInit(): array

 

copy
protected function beforeInit()
{
    $this->locales([
        'en' => 'English',
        'de' => 'Deutsch',
        'jp' => '日本人',
    ]);
}

Alias for admin_user() function.

admin()

 

copy
$admin = $this->admin();

Override list functionality. Show records list.

list(Request $request)

$request - request instance, your FormRequest in most cases.

 

copy
public function list(Request $request)
{
    $this->notifySmallInfo('Beware of', 'Well.. just beware');

    return parent::list($request);
}

Override search functionality.

search(Request $request)

$request - request instance, your FormRequest in most cases.

 

copy
public function list(Request $request)
{
    return parent::search($request);
}

Override create functionality. Show create form.

create(Request $request)

$request - request instance, your FormRequest in most cases.

 

copy
public function create(Request $request)
{
    return parent::create($request);
}

Override store functionality. Creating entity from form's data.

store(Request $request)

$request - request instance, your FormRequest in most cases.

 

copy
public function store(Request $request)
{
    $response = parent::store($request);

    event(new ItemCreatedByAdmin($this->model(), $this->admin()));

    return $response;
}

Override create functionality. Show edit form.

edit(Request $request, $id)

$request - request instance, your FormRequest in most cases.
$id - identifier of entity.

 

copy
public function edit(Request $request, $id)
{
    return parent::edit($request, $id);
}

Override create functionality. Updating entity.

update(Request $request, $id)

$request - request instance, your FormRequest in most cases.
$id - identifier of entity.

 

copy
public function update(Request $request, $id)
{
    return parent::update($request, $id);
}

Override inline functionality. Updating one field.

inline(Request $request)

$request - request instance, your FormRequest in most cases.

 

copy
public function inline(Request $request)
{
    return parent::inline($request);
}

Override delete functionality.

delete(Request $request, $id)

$request- request instance, your FormRequest in most cases.
$id - identifier of deleting entity.

 

copy
public function delete(DeleteRequest $request, $id)
{
    return parent::delete($request, $id);
}

Override restore functionality.

restore(Request $request, $id)

$request- request instance, your FormRequest in most cases.
$id - identifier of entity that should be restored.

 

copy
public function restore(RestoreRequest $request, $id)
{
    return parent::restore($request, $id);
}

Override force delete functionality.

forceDelete(Request $request, $id)

$request- request instance, your FormRequest in most cases.
$id - identifier of entity that should be force deleted.

 

copy
public function forceDelete(RestoreRequest $request, $id)
{
    return parent::forceDelete($request, $id);
}

Check if current admin user allowed to perform action.

can($action): bool

 

copy
protected function can($action): bool
{
    return $this->admin()->name === 'Me';
}
There is attribute $permissions for easily specifying permissions for CRUD table. Permissions can be specified as array and as string.
As array:
copy
protected $permissions = [
    'list'        => 'posts:list',
    'search'      => 'posts:search',
    'create'      => 'posts:create',
    'store'       => 'posts:store',
    'edit'        => 'posts:edit',
    'update'      => 'posts:update',
    'inline'      => 'posts:inline',
    'delete'      => 'posts:delete',
    'restore'     => 'posts:restore',
    'forceDelete' => 'posts:force-delete',
];
Where key is performed action and value is permission name, that should be checked against admin user.
Currently there are 10 action: list, search, create, store, edit, update, inline, delete, restore, forceDelete.
If some action is skipped in permission's array, then it will count as permission passed.
As string:
copy
protected $permissions = 'posts';
Will work same way as you'll define permissions as in array example above. E.g., for list action it will take your permissions string posts and prepend :list to retrieve permission that will be checked.

Trigger flash notification.

notify(string $title [, string $content = null [, int $timeout = 4000 [, string $color = null [, string $icon = null [, string $type = 'small']]]]])

$title - title of notification.
$content - body of notification.
$timeout - show timeout in ms. Pass 0 for showing notification until user's interaction.
$color - notification color: hex or valid color name.
$icon - classes for icon element.
$type - type of notification: small or big.

There are aliases for notifications with predefined type, icon, and color:

notifySmall(string $title [, string $content = null [, int $timeout = 4000 [, string $color = null [, string $icon = null]]]])
notifyBig(string $title [, string $content = null [, int $timeout = 4000 [, string $color = null [, string $icon = null]]]])

notifySmallSuccess(string $title [, string $content = null [, int $timeout = 4000]])
notifySmallDanger(string $title [, string $content = null [, int $timeout = 4000]])
notifySmallWarning(string $title [, string $content = null [, int $timeout = 4000]])
notifySmallInfo(string $title [, string $content = null [, int $timeout = 4000]])

notifyBigSuccess(string $title [, string $content = null [, int $timeout = 4000]])
notifyBigDanger(string $title [, string $content = null [, int $timeout = 4000]])
notifyBigWarning(string $title [, string $content = null [, int $timeout = 4000]])
notifyBigInfo(string $title [, string $content = null [, int $timeout = 4000]])

 

copy
$this->notify('Success', 'Success as always', 8000, 'green');

Return array of additional templates, that will be rendered above table in list view.

getListViewsAbove(): array

 

copy
protected function getListViewsAbove(): array
{
    return [
        view('template'),
    ];
}

Return array of additional templates, that will be rendered below table in list view.

getListViewsBelow(): array

 

copy
protected function getListViewsBelow(): array
{
    return [
        view('template'),
    ];
}

Return array of additional templates, that will be rendered above form in create view.

getCreateViewsAbove(): array

 

copy
protected function getCreateViewsAbove(): array
{
    return [
        view('template'),
    ];
}

Return array of additional templates, that will be rendered below form in create view.

getCreateViewsBelow(): array

 

copy
protected function getCreateViewsBelow(): array
{
    return [
        view('template'),
    ];
}

Return array of additional templates, that will be rendered above form in edit view.

getEditViewsAbove(): array

 

copy
protected function getEditViewsAbove(): array
{
    return [
        view('template'),
    ];
}

Return array of additional templates, that will be rendered below form in edit view.

getEditViewsBelow(): array

 

copy
protected function getEditViewsBelow(): array
{
    return [
        view('template'),
    ];
}

Method for exceptions interception that are catchable by package. Non-null values will be treated as response.

onException(\Throwable $exception)

 

copy
protected function onException(\Throwable $exception)
{
    Log::error($exception);
}
copy
protected function onException(\Throwable $exception)
{
    $this->notifySmallSuccess($exception->getMessage());

    return redirect(admin_url('posts', [42]));
}

Fields

Overview

To create field call static make method:

copy
Text::make('first_name');

second optional parameter is for field's label

copy
Text::make('first_name', 'Client name');

or skip it to generate it from field's name.

Markup Fields

Text
<input type="text" /> field.

copy
Text::make('title')->tooltip('A flailing monkey bathes in sunlight.');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
tooltip($message) Set message for field's tooltip.

Parameters:

$message - tooltip message.

copy
->tooltip('Some useful information')
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) Enable clipboard button in list view to copy column's value.

Parameters:

$enabled- on/off flag. $caption- caption for the copy button; can be \Closure, that at first argument receives $model object.

copy
->clipboard()
copy
->clipboard(true, 'Click to copy!')
copy
->clipboard(true, function ($model) {
    return 'copy #'. $model->id;
})
inline([bool $enabled = true, array $options = []]) Enable inline edit in list view to change column's value.

Parameters:

$enabled - on/off flag.
$options - array of x-editable.js plugin options. reference

Column will be validating under its rules in FormRequest class at update method, if present.

copy
->inline()
copy
->inline(true, [
    'placement' => 'left',
])
translatable([bool $translatable = true]) Enable translatable tabs for input.

Parameters:

$translatable - on/off translatable behavior.

Locales should be setted in controller's init() method via locales helper method. Translatable functionality is based on spatie/laravel-translatable, so HasTranslations trait should be added to model and field need to specified in $translatable array.

copy
->translatable()
mask(string $pattern [, string $placeholder = '∗']) Add mask to input.

Parameters:

$pattern - pattern for placeholder; a - represents an alpha character (A-Z,a-z), 9 - represents a numeric character (0-9), * - epresents an alphanumeric character (A-Z,a-z,0-9).
$placeholder - placeholder character.

copy
->mask('(999) 999-9999')
copy
->mask('aaa/aaa', '_')
maxlength(int $length) Define maxlength attribute length for field's input.

Parameters:

$length - length value for maxlength attribute.

copy
->maxlength(42)

Textarea
<textarea></textarea> field.

copy
Textarea::make('title')->rows(5);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
tooltip($message) Set message for field's tooltip.

Parameters:

$message - tooltip message.

copy
->tooltip('Some useful information')
rows(int $rows) Set rows value for input.

Parameters:

$rows - value for rows attribute.

copy
->rows(6)
resizable([bool $resizable = true]) Make field resizable.

Parameters:

$resizable - should field be resizable.

copy
->resizable()
expandable([bool $expandable = true]) Make field expandable.

Parameters:

$expandable - should field be expandable.

copy
->expandable()
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) Enable clipboard button in list view to copy column's value.

Parameters:

$enabled- on/off flag. $caption- caption for the copy button; can be \Closure, that at first argument receives $model object.

copy
->clipboard()
copy
->clipboard(true, 'Click to copy!')
copy
->clipboard(true, function ($model) {
    return 'copy #'. $model->id;
})
inline([bool $enabled = true, array $options = []]) Enable inline edit in list view to change column's value.

Parameters:

$enabled - on/off flag.
$options - array of x-editable.js plugin options. reference

Column will be validating under its rules in FormRequest class at update method, if present.

copy
->inline()
copy
->inline(true, [
    'placement' => 'left',
])
translatable([bool $translatable = true]) Enable translatable tabs for input.

Parameters:

$translatable - on/off translatable behavior.

Locales should be setted in controller's init() method via locales helper method. Translatable functionality is based on spatie/laravel-translatable, so HasTranslations trait should be added to model and field need to specified in $translatable array.

copy
->translatable()
maxlength(int $length) Define maxlength attribute length for field's input.

Parameters:

$length - length value for maxlength attribute.

copy
->maxlength(42)

Checkbox
<input type="checkbox" /> field.

copy
Checkbox::make('is_published', 'Published');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())

Number
<input type="number" /> field.

copy
Number::make('price');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
tooltip($message) Set message for field's tooltip.

Parameters:

$message - tooltip message.

copy
->tooltip('Some useful information')
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) Enable clipboard button in list view to copy column's value.

Parameters:

$enabled- on/off flag. $caption- caption for the copy button; can be \Closure, that at first argument receives $model object.

copy
->clipboard()
copy
->clipboard(true, 'Click to copy!')
copy
->clipboard(true, function ($model) {
    return 'copy #'. $model->id;
})
inline([bool $enabled = true, array $options = []]) Enable inline edit in list view to change column's value.

Parameters:

$enabled - on/off flag.
$options - array of x-editable.js plugin options. reference

Column will be validating under its rules in FormRequest class at update method, if present.

copy
->inline()
copy
->inline(true, [
    'placement' => 'left',
])
translatable([bool $translatable = true]) Enable translatable tabs for input.

Parameters:

$translatable - on/off translatable behavior.

Locales should be setted in controller's init() method via locales helper method. Translatable functionality is based on spatie/laravel-translatable, so HasTranslations trait should be added to model and field need to specified in $translatable array.

copy
->translatable()
min(float $min) Set min attribute.

Parameters:

$min - specifies the minimum value allowed.

copy
->min(4)
max(float $max) Set max attribute.

Parameters:

$max - specifies the maximum value allowed.

copy
->max(42)
step(float $step) Set step attribute.

Parameters:

$step - specifies the interval between legal numbers in an input field.

copy
->step(2)

Radio
<input type="radio" /> field.

copy
Radio::make('type')->options([
    'simple_type' => 'Simple',
    'extended_type' => 'Extended',
    'super_type' => 'Supadupa',
]);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
options(array $options) Set array of available options.

Parameters:

$options - options array. Array key represents option's value, that will be saved into database, and array value - displayed option's title.

copy
->options([
    'active'   => 'Post is active',
    'disabled' => 'Post is suspended',
])

For Select field $options can be multidimensional array to group options.

copy
->options([
    'active' => 'Post is active',
    'Group with inactive statuses' => [
        'disabled' => 'Post is suspended',
        'trashed' => 'Post is trashed',
    ],
])
columns(int $columns) By how many columns should options or relation values be divided.

Parameters:

$columns - columns count. default: 1.

copy
->columns(3)
relation(string $method, string $titleField [, string $groupTitle = '']) Add relation dependency for field.

Parameters:

$method - relation method name.
$titleField - field name that should be used to display title of related entity.
$groupTitle - group for relation options, used only for morphedByMany relation.

copy
->relation('posts', 'title')
copy
// or for morphedByMany
->relation('valets', 'name', 'Car valets')->relation('owners', 'name', 'Car owners')
addCondition(\Closure $callback) Add clause for getting relation options.

Parameters:

$callback - closure for additional clause.

copy
->addCondition(function($query) {
    $query->where('is_active', true);
})
relationSearch(\Closure $callback) Define custom search callback for querying additional options with ajax enabled.

Parameters:

$callback - closure to override search functionality.

Default behavior: ->where($fieldName, $searchQuery).

`Select` field: works only for select2 type with ajax enabled and setted relations.

copy
->relationSearch(function($relatedModel, $relationTitleField, $searchQuery) {
    return $relatedModel->where($relationTitleField, strtolower($searchQuery));
})

Select
<select></select> field.

copy
Select::make('fruit')->relation('fruit', 'name');
copy
Select::make('fruit')->relation('fruit', 'name')->type('select2');
// or
Select::make('fruit')->relation('fruit', 'name')->type(Select::SELECT_2);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
type(string $type) Set field's type.

Parameters:

$type- type of field.

Wysiwyg

  • summernote (default)
  • tinymce
ColorPicker
  • hex (default)
  • rgba
Select
  • simple (default)
  • select2

copy
->type('select2')
copy
->type(ColorPicker::RGBA)
options(array $options) Set array of available options.

Parameters:

$options - options array. Array key represents option's value, that will be saved into database, and array value - displayed option's title.

copy
->options([
    'active'   => 'Post is active',
    'disabled' => 'Post is suspended',
])

For Select field $options can be multidimensional array to group options.

copy
->options([
    'active' => 'Post is active',
    'Group with inactive statuses' => [
        'disabled' => 'Post is suspended',
        'trashed' => 'Post is trashed',
    ],
])
relation(string $method, string $titleField [, string $groupTitle = '']) Add relation dependency for field.

Parameters:

$method - relation method name.
$titleField - field name that should be used to display title of related entity.
$groupTitle - group for relation options, used only for morphedByMany relation.

copy
->relation('posts', 'title')
copy
// or for morphedByMany
->relation('valets', 'name', 'Car valets')->relation('owners', 'name', 'Car owners')
addCondition(\Closure $callback) Add clause for getting relation options.

Parameters:

$callback - closure for additional clause.

copy
->addCondition(function($query) {
    $query->where('is_active', true);
})
relationSearch(\Closure $callback) Define custom search callback for querying additional options with ajax enabled.

Parameters:

$callback - closure to override search functionality.

Default behavior: ->where($fieldName, $searchQuery).

`Select` field: works only for select2 type with ajax enabled and setted relations.

copy
->relationSearch(function($relatedModel, $relationTitleField, $searchQuery) {
    return $relatedModel->where($relationTitleField, strtolower($searchQuery));
})
multiple([bool $multiple = true]) Flag field as multiple.

Parameters:

$multiple- switch multiple flag for field.

Attribute should be casted to array in model's $cast if it's not relation field.
copy
->multiple()
ajax([bool ajax = true]) Enable ajax search for `Select` field with select2 type, or for `Tags` field.

Parameters:

$ajax - flag to enable/disable ajax search for select2 input.

`Select` field: works only for select2 type with setted relations.

copy
->ajax()

Tags
It's select2 plugin with tags mode enabled.
Can be used for many2many relations, on which all new options will be created before assigning to entity, when relation() method was called.
And for storing array values when relation() method was not applied.

copy
Tags::make('ips')->relation('ips', 'ip')->hideOptions();
copy
Tags::make('phones');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
relation(string $method, string $titleField [, string $groupTitle = '']) Add relation dependency for field.

Parameters:

$method - relation method name.
$titleField - field name that should be used to display title of related entity.
$groupTitle - group for relation options, used only for morphedByMany relation.

copy
->relation('posts', 'title')
copy
// or for morphedByMany
->relation('valets', 'name', 'Car valets')->relation('owners', 'name', 'Car owners')
hideOptions([bool $hide = true]) Do not suggest available tags. Defaults to true when no relation specified.

Parameters:

$hide - disable available tags suggestions.

copy
->hideOptions()
addCondition(\Closure $callback) Add clause for getting relation options.

Parameters:

$callback - closure for additional clause.

copy
->addCondition(function($query) {
    $query->where('is_active', true);
})
relationSearch(\Closure $callback) Define custom search callback for querying additional options with ajax enabled.

Parameters:

$callback - closure to override search functionality.

Default behavior: ->where($fieldName, $searchQuery).

`Select` field: works only for select2 type with ajax enabled and setted relations.

copy
->relationSearch(function($relatedModel, $relationTitleField, $searchQuery) {
    return $relatedModel->where($relationTitleField, strtolower($searchQuery));
})
ajax([bool ajax = true]) Enable ajax search for `Select` field with select2 type, or for `Tags` field.

Parameters:

$ajax - flag to enable/disable ajax search for select2 input.

`Select` field: works only for select2 type with setted relations.

copy
->ajax()

Password
<input type="password" /> field.

copy
Password::make('password');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
hash($hash) Set hash function.

Parameters:

$hash - closure or hash function name, used to hash password value; or null to save passwords as-is. bcrypt by default.

copy
->hash('bcrypt')
copy
->hash('md5')
copy
->hash(function($value) {
    return sha1($value);
})

Hidden
<input type="password" /> field.
Pass extra values to form handlers for validation rules or smth else.

copy
Hidden::make('my_hidden_field')->default('hidden_field_value');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()

ColorPicker
Color picker plugin field for hex and rgba values.

copy
ColorPicker::make('sektor', 'Sektor color');
copy
ColorPicker::make('cyrax', 'Cyrax color')->type('rgba');
// or
ColorPicker::make('cyrax', 'Cyrax color')->type(ColorPicker::RGBA);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
type(string $type) Set field's type.

Parameters:

$type- type of field.

Wysiwyg

  • summernote (default)
  • tinymce
ColorPicker
  • hex (default)
  • rgba
Select
  • simple (default)
  • select2

copy
->type('select2')
copy
->type(ColorPicker::RGBA)

IconPicker
Icon picker plugin field for FontAwesome 4.7.0 value.

copy
IconPicker::make('icon');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())

Markdown
Markdown text editor.

copy
Markdown::make('content');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())

Wysiwyg
Summernote wysiwyg editor.

copy
Wysiwyg::make('content');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) Add order button to field column.

Parameters:

$orderable - activate/disable order button for field.

$overridedOrderCallback - closure to redefine order functionality.

copy
->orderable()
copy
// if your database support arrow access to json keys
->orderable(true, function ($model, $field, $direction, &$shouldApplyDefaultOrder) {
    $name = $field->name();
    if ($field->isTranslatable()) {
        $name = $name .'->'. $this->crud()->getCurrentLocale();
    }

    $model->orderBy($name, $direction);
    $shouldApplyDefaultOrder = false;
})
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
type(string $type) Set field's type.

Parameters:

$type- type of field.

Wysiwyg

  • summernote (default)
  • tinymce
ColorPicker
  • hex (default)
  • rgba
Select
  • simple (default)
  • select2

copy
->type('select2')
copy
->type(ColorPicker::RGBA)
translatable([bool $translatable = true]) Enable translatable tabs for input.

Parameters:

$translatable - on/off translatable behavior.

Locales should be setted in controller's init() method via locales helper method. Translatable functionality is based on spatie/laravel-translatable, so HasTranslations trait should be added to model and field need to specified in $translatable array.

copy
->translatable()
options(array $options) Set options for selected wysiwyg editor.

Parameters:

$options - array of options.

copy
->type('summernote')->options([
    'height' => 400,
    ['font', ['bold', 'italic', 'underline', 'clear']],
    ['view', ['codeview', 'fullscreen']],
])
copy
->type('tinymce')->options([
    'plugins' => 'code table lists autoresize link',
    'menubar' => false,
    'toolbar' => 'undo redo | bold italic | link | numlist bullist | table | styleselect | removeformat | code',
])

File
<input type="file" /> field.

copy
File::make('pdf', 'Some pdf file')->disk('public');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
multiple([bool $multiple = true]) Flag field as multiple.

Parameters:

$multiple- switch multiple flag for field.

Attribute should be casted to array in model's $cast if it's not relation field.
copy
->multiple()
disk(string $disk) Set filesystem disc name, specified at filesystems.disks.

Parameters:

$disk- filesystem disk name. filesystems.default config value by default.

copy
->disk('public')
path(string $path) Set path for storing file.

Parameters:

$path- path for storing.

copy
->path('public')
filename([Closure $filenameClosure) Set closure for changing filename upon upload.

Parameters:

$filenameClosure - closure for overriding filename.

copy
->filename(function($file, $request, $imageData, $isOriginalImage) {
    $isRecropFromOriginal = !$file && !$isOriginalImage;
    $extension = $isRecropFromOriginal ? pathinfo($imageData['sources']['original'], PATHINFO_EXTENSION) : $file->extension();
    $filename = Str::random(40) .'.'. $extension;

    if ($isRecropFromOriginal) {
        return 'recrop-'. $filename;
    }
    if ($isOriginalImage) {
        return 'original-'. $filename;
    }
    if (!$isOriginalImage) {
        return 'crop-'. $filename;
    }

    return $filename;
})

Image
Widget field with ability to crop, preview image, rotate cropped image, and set background color for uncovered corners.

copy
Image::make('background')->crop()->ratio(800, 300);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
multiple([bool $multiple = true]) Flag field as multiple.

Parameters:

$multiple- switch multiple flag for field.

Attribute should be casted to array in model's $cast if it's not relation field.
copy
->multiple()
disk(string $disk) Set filesystem disc name, specified at filesystems.disks.

Parameters:

$disk- filesystem disk name. filesystems.default config value by default.

copy
->disk('public')
path(string $path) Set path for storing file.

Parameters:

$path- path for storing.

copy
->path('public')
crop([bool $crop = true]) Add ability to crop image after it's selected via input.

Parameters:

$crop- flag to enable/disable image croping.

copy
->crop()
ratio(int $width, int $height) Set aspect ratio for cropping selection.

Parameters:

$width - width for aspect ratio.
$height - height for aspect ratio.

Works only with crop enabled.

copy
->ratio(4, 3)
copy
->ratio(1200, 600)
encode([bool $encode = true]) Should image be encoded to base64 string.

Parameters:

$encode- flag to enable/disable image encoding.

copy
->encode()
autoOpen([bool $shouldAutoOpen = true]) Should image field always open modal for image manipulation.

Parameters:

$shouldAutoOpen - enables image field auto open functionality.

copy
->autoOpen(false)
filename([Closure $filenameClosure) Set closure for changing filename upon upload.

Parameters:

$filenameClosure - closure for overriding filename.

copy
->filename(function($file, $request, $imageData, $isOriginalImage) {
    $isRecropFromOriginal = !$file && !$isOriginalImage;
    $extension = $isRecropFromOriginal ? pathinfo($imageData['sources']['original'], PATHINFO_EXTENSION) : $file->extension();
    $filename = Str::random(40) .'.'. $extension;

    if ($isRecropFromOriginal) {
        return 'recrop-'. $filename;
    }
    if ($isOriginalImage) {
        return 'original-'. $filename;
    }
    if (!$isOriginalImage) {
        return 'crop-'. $filename;
    }

    return $filename;
})

Date
Datepicker field.

copy
Date::make('birthdate')->months(3);
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
inline([bool $enabled = true, array $options = []]) Enable inline edit in list view to change column's value.

Parameters:

$enabled - on/off flag.
$options - array of x-editable.js plugin options. reference

Column will be validating under its rules in FormRequest class at update method, if present.

copy
->inline()
copy
->inline(true, [
    'placement' => 'left',
])
months(int $months) Set months count to be shown.

Parameters:

$months - months count.

copy
->months(3)
format(string $momentJsFormat) Set date fromat.

Parameters:

$momentJsFormat - moment.js date format; will be displayed on frontend.

copy
->format('DD/MM YY')

Datetime
Datetimepicker field.

copy
Datetime::make('published_at');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
format(string $momentJsFormat) Set date fromat.

Parameters:

$momentJsFormat - moment.js date format; will be displayed on frontend.

copy
->format('DD/MM YY')

Time
Time field.

copy
Time::make('close_time');
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
readonly([bool $isReadonly = true]) Set field to readonly state.

Parameters:

$isReadonly - flag to on/off readonly state.

copy
->readonly()
placeholder($placeholder) Placeholder for field.

Parameters:

$placeholder - field's placeholder.

copy
->placeholder('7100 Athens Place')
default($value) Field's default value.

Parameters:

$value - default value for field in create form.

For Date, Time, and Datetime fields $value can be instance of \DateTime.

copy
->default(100)
copy
->default(now())
nullable([bool $isNullable = true]) Make field nullable; false values will be converted to null.

Parameters:

$isNullable - should field be nullables.

copy
->nullable()
placement(string $placement) Set position for clock picker.

Parameters:

$placement - one of four positions.

Available options:

  • bottom (default)
  • left
  • top
  • rigth

copy
->placement('top')
copy
->placement(Time::TOP)

Repeater
Repeater field.

copy
Repeater::make('data')->fields([
    Text::make('title')->col(6),
    File::make('file')->disk('public')->col(6),
    Image::make('image')->crop()->multiple()->disk('public')->col(12),
]),
method description
name(string $name) Name of field - database column name or model mutator.
Mandatory, only if you skip passing name parameter in make method.

Parameters:

$name - input's name.

copy
->name('field')
title(string $title) Label of field.

Parameters:

$title - input's label.

copy
->title('Address')
col(int $col) Set col size for <div> of field's input.

Parameters:

$col - col size for row.

copy
->col(4)
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
translatable([bool $translatable = true]) Enable translatable tabs for input.

Parameters:

$translatable - on/off translatable behavior.

Locales should be setted in controller's init() method via locales helper method. Translatable functionality is based on spatie/laravel-translatable, so HasTranslations trait should be added to model and field need to specified in $translatable array.

copy
->translatable()
width(int $width) Set width for field's column in list view of table.

Parameters:

$width - width for column in percentage.

copy
->width(5)
sortable([bool $enable = true) Enable sortable functionality for dragging repeater's items.

Parameters:

$enable- on/off flag.

copy
->sortable()
fields([array $fields]) Add fields that should be rendered int repeater item.

Parameters:

$fields- array of fields objects.

copy
->fields([
    Text::make('title')->col(6),
    Text::make('caption')->col(6),
])
heading([string $fieldName]) Specify repeater's field name that should be rendered as heading for repeater's item. Also headings are displayed in list value.

Parameters:

$fieldName- repeater's field name.

copy
->heading('title')

RowMarkup
Markup field for wrapping fields in <div class="row"></div>.

copy
RowMarkup::make()->fields([
    Text::make('title')->col(4),
    Textarea::make('description')->col(8),
]);

DummyField
Dummy field, just as stated. Usually used to create some offsets in create/edit form.

copy
DummyField::make()->col(4);

Columns

Columns are the same as fields. By default all fields are behave as columns too.

There are several ways to assign them: passing field's name or field's object.

Multiple columns at once:

copy
$this->addFields([
    Text::make('id')->readonly(),
    'title',
    'description',
]);

Or by one column:

copy
$this->addField(Text::make('id')->readonly());
$this->addField('title');

Columns will be shown in table in order as they were specified.

Filters

Overview

Filters are used to add search/filter input above corresponding field column.

TextFilter

copy
Text::make('title')->filter(TextFilter::make());
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
like([$left = true [, $right = true]]) Query with like operator with wildcards on the both of sides.

Parameters:

$left - should wildcard be prepended to value.

$right - should wildcard be appended to value.

Any position of wildcard will force like use, even if different sign is setted.

copy
->like(true, false)

TextareaFilter

copy
Textarea::make('description')->filter(TextareaFilter::make());
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
like([$left = true [, $right = true]]) Query with like operator with wildcards on the both of sides.

Parameters:

$left - should wildcard be prepended to value.

$right - should wildcard be appended to value.

Any position of wildcard will force like use, even if different sign is setted.

copy
->like(true, false)

NumberFilter

copy
Number::make('price')->filter(NumberFilter::make());
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
like([$left = true [, $right = true]]) Query with like operator with wildcards on the both of sides.

Parameters:

$left - should wildcard be prepended to value.

$right - should wildcard be appended to value.

Any position of wildcard will force like use, even if different sign is setted.

copy
->like(true, false)

SelectFilter

copy
Select::make('posts')->relation('posts', 'title')->filter(SelectFilter::make());
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
multiple([bool $multiple = true]) Enable select multiple values.

Parameters:

$multiple - should filter allow to select multiple values.

Field's multiple value will be used, if filter's multiple value left unchanged.

copy
->multiple()
options(array $options) Set options list for select input.

Parameters:

$options - array of options, like in Select field.

Field's options value will be used, if filter's options value left unchanged.

copy
->options([
    '0' => 'Inactive',
    '1' => 'Active',
])

DateFilter

copy
Datetime::make('created_at')->filter(DateFilter::make()->range());
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
range([bool $enable = true]) Enable range selection.

Parameters:

$enable - enable date range selection.

Enabled range will use its own comparison signs, so sign will be omitted.

copy
->like(true, false)

CheckboxFilter

copy
Checkbox::make('is_active', 'Status')->filter(CheckboxFilter::make()->titles('Active', "Inactive', 'Any'));
method description
sign(string $sign) Change comparison sign for filtering by value.

Parameters:

$sign - sign that should be used for comparison in query. Default is =.

copy
->sign('<')
range([bool $enable = true]) Enable range selection.

Parameters:

$enable - enable date range selection.

Enabled range will use its own comparison signs, so sign will be omitted.

copy
->like(true, false)
titles([string $checked = null [, string $unchecked = null [, string $desearch = null]]]) Set captions for filter's input.

Parameters:

$checked - caption for true value.

$unchecked - caption for false value.

$desearch - caption for any value, same as "plz, stop searching".

Pass null to leave caption unchanged.

copy
->titles(null, null, 'All')

Actions

Adding actions to table row

By default there are activated three action buttons: create, edit, and delete.

Buttons restore and force-delete will be added if controller has ->softDeletes(true).

You can disable any action button in two ways:

copy
$this->action('delete')->check(function () {
    return false;
});
// or
$this->removeAction('delete');

Creating custom action button:

You can implement Yaro\Jarboe\Table\Actions\ActionInterface interface, or extend Yaro\Jarboe\Table\Actions\AbstractAction

copy
class ShowAction implements ActionInterface
{
    public function identifier()
    {
        // TODO: Implement identifier() method.
    }

    public function render($model = null)
    {
        // TODO: Implement render() method.
    }

    public function isAllowed($model = null)
    {
        // TODO: Implement isAllowed() method.
    }
}

Yaro\Jarboe\Table\Actions\AbstractAction already had implemented identifier and isAllowed methods.

copy
class ShowAction extends AbstractAction
{
    public function render($model = null)
    {
        return view('actions.show', compact('model'));
    }
}

Initialize your custom action in init method of your crud table controller:

copy
$this->addAction(ShowAction::make());

Additionally you can specify it's position:

copy
$this->addAction(ShowAction::make(), 'before', 'delete');
// or
$this->addAction(ShowAction::make(), 'after', 'edit');

Toolbar

What is toolbar?

In simple words this is container for your tools. Tool can be anything you want: custom filter inputs, some mass action button, graph, or even just a simple message for user.

Tool can be placed in header of table's wrapper, on top of table rows, under them, and on top and under at the same time.

There are some tools in package already:

1. \Yaro\Jarboe\Table\Toolbar\ShowHideColumnsTool injects in header and adds ability to choose what columns should be showed. Just add it in your init method.

copy
$this->addTool(new ShowHideColumnsTool());

2. \Yaro\Jarboe\Table\Toolbar\MassDeleteTool enables checkboxes on each row and adds button for bulk deleting.

copy
$this->addTool(new MassDeleteTool());

3. \Yaro\Jarboe\Table\Toolbar\MassRestoreTool enables checkboxes on each row and adds button for bulk restoring.

copy
$this->addTool(new MassRestoreTool());

How to make your own tool?

Helpers

Overview

Simply helper functions.

admin_url
Generates fully qualified admin url for passed path.

copy
admin_url('users');
// http://localhost/admin/users

admin_user_guard
Returns admin's guard name.

copy
admin_user_guard();
// admin

admin_user
Returns admin user object. Wrapper for auth(admin_user_guard())->user().

copy
$admin = admin_user();

admin_auth
Get the available auth instance.. Wrapper for auth(admin_user_guard()).
Admin panel guard is set as default one when auth() is called under admin panel's routes.

copy
$idAdmin = admin_auth()->id();

urlify
Convert utf8 strings to ASCII strings which can be used as readable URL-segments.

copy
$slug = urlify("Omelette à l'ancienne!");
// omelette-lancienne

Blade directives

Overview

Custom blade directives available in package.

Directives

pushonce
Works the same as push directive, but with one small difference: pushed codeblock will be stacked only once.

copy
@pushonce('scripts', <script src="/js/super.min.js"></script>)
copy
@pushonce('styles', <style>
    div > span {
        color: mistyrose;
     }
</style>)

How to's

Create custom field

In this example we'll make custom field to make slug from field's value that will be passed in request.

  1. Create class for new field that extends from Yaro\Jarboe\Table\Fields\AbstractField.
  2. Define abstract methods for render purposes: getListView, getEditFormView, and getCreateFormView;
  3. Define method makeFrom for setting field's name that should be slugged.
  4. Override value method for retrieving value that will be passed to model. There will be placed code for slugging string.

copy
use Yaro\Jarboe\Table\Fields\AbstractField;
use Illuminate\Http\Request;

class Slug extends AbstractField
{
    private $sluggableFromField;

    public function makeFrom(string $fieldName)
    {
        $this->sluggableFromField = $fieldName;

        return $this;
    }

    public function value(Request $request)
    {
        $value = $request->get($this->sluggableFromField);

        return urlify($value);
    }

    public function getListView($model)
    {
        $template = 'list';

        return view(''admin.fields.slug.list, [
            'model' => $model,
            'field' => $this,
        ]);
    }

    public function getEditFormView($model)
    {
        return view('admin.fields.slug.edit', [
            'model' => $model,
            'field' => $this,
        ]);
    }

    public function getCreateFormView()
    {
        $makeFromField = $this->crud()->getFieldByName($this->sluggableFromField);

        return view('admin.fields.slug.create', [
            'field' => $this,
            'makeFromField' => $makeFromField,
        ]);
    }
}

  1. Create views that will be rendered for this field for representing model's value.

copy
{{-- resources/views/admin/fields/slug/list.blade.php --}}

{{ $field->getAttribute($model) }}
copy
{{-- resources/views/admin/fields/slug/create.blade.php --}}

<label class="label">
    {{ $field->title() }}
</label>

<label class="input {{ $errors->has($field->name()) ? 'state-error' : '' }}">
    <input type="text" name="{{ $field->name() }}" value="{{ $field->oldOrDefault($model) }}">
    <small>slug will be created from "{{ $makeFromField->title() }}"</small>

    @foreach ($errors->get($field->name() as $message)
        
{{ $message }}
@endforeach </label>
copy
{{-- resources/views/admin/fields/slug/edit.blade.php --}}

<label class="label">
    {{ $field->title() }}
</label>

<label class="input {{ $errors->has($field->name()) ? 'state-error' : '' }}">
    <input type="text" name="{{ $field->name() }}" value="{{ $field->oldOrAttribute($model) }}">
    <small>slug will be created from "{{ $makeFromField->title() }}"</small>

    @foreach ($errors->get($field->name() as $message)
        
{{ $message }}
@endforeach </label>

Now you can use it in controller that defines table.

copy
public function init()
{
    // ...

    $this->addFields([
        Text::make('title'),
        Slug::make('slug')->makeFrom('title'),
    ]);
          
    // ...
}

Create custom action button

For news posts it might be useful to have action button that opens post's page. So here's how to do it:

  1. Create class that extends Yaro\Jarboe\Table\Actions\AbstractAction.
  2. Define render method that is mandatory by interface for rendering button.

copy
use Yaro\Jarboe\Table\Actions\AbstractAction;

class ShowPostAction extends AbstractAction
{
    public function render($model = null)
    {
        return view('admin.actions.show_post', compact('model'));
    }
}

  1. Create view resources/views/admin/actions/show_post.blade.php;

copy
<a class="btn btn-default btn-sm"
      target="_blank"
      href="{{ route('post', ['post' => $model->id]) }}">
    <i class="fa fa-eye"></i>
</a>

New action button is ready. Now it can be placed before edit action button.

copy
public function init()
{
    // ...

    $this->addAction(ShowPostAction::make(), 'before', 'edit');

    // ...
}