Installation
Add package to your composer.json
:
composer require yaro/jarboe
Follow installer steps:
php artisan jarboe:install
Add command to composer.json
for automatic assets update:
"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
php artisan make:migration create_posts_table
And update it’s up
method
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
php artisan migrate
Create model
php artisan make:model Post
Specify fillables and casting
class Post extends Model
{
protected $fillable = [
'title',
'content',
'is_published',
];
protected $casts = [
'is_published' => 'boolean',
];
}
Create controller and define routes
php artisan make:controller PostsController
Then extend new controller class from AbstractTableController
and declare init
method
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
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
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
<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. setsubdomain_panel_enabled
totrue
in/app/config/jarboe/admin_panel.php
.
2. check yourSESSION_DOMAIN
in.env
file (for Laravel version>=5.4
, ordomain
in thesessions.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
.copyclass PostsController extends AbstractTableController { protected $viewCrudCreate = 'my_crud_create_view'; // }
-
How to add locales switcher in admin panel?
You can define localeslist
andcurrent
locale injarboe/locales.php
configuration files. -
How to change auth guard for admin panel?
Add newguard
andprovider
inconfig/auth.php
:copySpecify newly created'guards' => [ // 'admin' => [ 'driver' => 'session', 'provider' => 'admins', ], ], // 'providers' => [ // 'admins' => [ 'driver' => 'eloquent', 'model' => \Yaro\Jarboe\Models\Admin::class, ], ],
guard
inconfig/jarboe/admin_panel.php
configuration file atauth_guard
key. That's it!
Set class name for crud. Mandatory.
$modelClass - class name of model.
copy
|
Add clauses to model instance.
$callback - closure that takes one parameter $model .
copy
|
Set how rows should be ordered.
$column - model field by which model query should add orderBy clause.
$direction - direction for orderBy clause, supports asc and desc .
copy
|
Add pagination to crud table.
$perPage - pagination value; pass array of integers for adding per page select at the bottom of table.
copy
copy
|
Add new field object.
$field - field object.
copy
|
Add multiple field objects.
$fields - array of fields objects.
copy
|
Add new tab and set fields to it.
$title - tab title.$fields - array of fields objects.
copy
|
Set field as column in crud table.
$column - field name.
copy
|
Set multiple columns.
$columns - array of field names.
copy
copy
|
Set locales for all translatable fields in table.
$locales - array of supported locales.
copy
copy
|
Add checkbox on the left side of each row for mass selection.
$enabled - enable/disable checkboxes.
copy
|
Allows to reorder table rows.
$field - name of weight field for sorting.
copy
|
Enable soft deletes for table. Actions for
|
Methods available in crud controller
Method that called before
|
Alias for
|
Override list functionality. Show records list.
$request - request instance, your FormRequest in most cases.
copy
|
Override search functionality.
$request - request instance, your FormRequest in most cases.
copy
|
Override create functionality. Show create form.
$request - request instance, your FormRequest in most cases.
copy
|
Override store functionality. Creating entity from form's data.
$request - request instance, your FormRequest in most cases.
copy
|
Override create functionality. Show edit form.
$request - request instance, your FormRequest in most cases.
$id - identifier of entity.
copy
|
Override create functionality. Updating entity.
$request - request instance, your FormRequest in most cases.
$id - identifier of entity.
copy
|
Override inline functionality. Updating one field.
$request - request instance, your FormRequest in most cases.
copy
|
Override delete functionality.
$request - request instance, your FormRequest in most cases.
$id - identifier of deleting entity.
copy
|
Override restore functionality.
$request - request instance, your FormRequest in most cases.
$id - identifier of entity that should be restored.
copy
|
Override force delete functionality.
$request - request instance, your FormRequest in most cases.
$id - identifier of entity that should be force deleted.
copy
|
Check if current admin user allowed to perform action.
copy
There is attribute
$permissions for easily specifying permissions for CRUD table. Permissions can be specified as array and as string.As array:
copy
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
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.
$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:
copy
|
Return array of additional templates, that will be rendered above table in list view.
copy
|
Return array of additional templates, that will be rendered below table in list view.
copy
|
Return array of additional templates, that will be rendered above form in create view.
copy
|
Return array of additional templates, that will be rendered below form in create view.
copy
|
Return array of additional templates, that will be rendered above form in edit view.
copy
|
Return array of additional templates, that will be rendered below form in edit view.
copy
|
Method for exceptions interception that are catchable by package. Non-null values will be treated as response.
copy
copy
|
Fields
Overview
To create field call static make
method:
Text::make('first_name');
second optional parameter is for field's label
Text::make('first_name', 'Client name');
or skip it to generate it from field's name.
Input Fields
Markup Fields
Text
<input type="text" />
field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
placeholder($placeholder) |
Placeholder for field. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
tooltip($message) |
Set message for field's tooltip. | |
Parameters:
|
copy
|
|
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) |
Enable clipboard button in list view to copy column's value. | |
Parameters:
|
copy
copy
copy
|
|
inline([bool $enabled = true, array $options = []]) |
Enable inline edit in list view to change column's value. | |
Parameters:
Column will be validating under its rules in |
copy
copy
|
|
translatable([bool $translatable = true]) |
Enable translatable tabs for input. | |
Parameters:
Locales should be setted in controller's |
copy
|
|
mask(string $pattern [, string $placeholder = '∗']) |
Add mask to input. | |
Parameters:
|
copy
copy
|
|
maxlength(int $length) |
Define maxlength attribute length for field's input.
|
|
Parameters:
|
copy
|
Textarea
<textarea></textarea>
field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
placeholder($placeholder) |
Placeholder for field. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
tooltip($message) |
Set message for field's tooltip. | |
Parameters:
|
copy
|
|
rows(int $rows) |
Set rows value for input.
|
|
Parameters:
|
copy
|
|
resizable([bool $resizable = true]) |
Make field resizable. | |
Parameters:
|
copy
|
|
expandable([bool $expandable = true]) |
Make field expandable. | |
Parameters:
|
copy
|
|
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) |
Enable clipboard button in list view to copy column's value. | |
Parameters:
|
copy
copy
copy
|
|
inline([bool $enabled = true, array $options = []]) |
Enable inline edit in list view to change column's value. | |
Parameters:
Column will be validating under its rules in |
copy
copy
|
|
translatable([bool $translatable = true]) |
Enable translatable tabs for input. | |
Parameters:
Locales should be setted in controller's |
copy
|
|
maxlength(int $length) |
Define maxlength attribute length for field's input.
|
|
Parameters:
|
copy
|
Checkbox
<input type="checkbox" />
field.
Checkbox::make('is_published', 'Published');
Number
<input type="number" />
field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
placeholder($placeholder) |
Placeholder for field. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
tooltip($message) |
Set message for field's tooltip. | |
Parameters:
|
copy
|
|
clipboard([bool $enabled = true, string|null|\Closure $caption = null]) |
Enable clipboard button in list view to copy column's value. | |
Parameters:
|
copy
copy
copy
|
|
inline([bool $enabled = true, array $options = []]) |
Enable inline edit in list view to change column's value. | |
Parameters:
Column will be validating under its rules in |
copy
copy
|
|
translatable([bool $translatable = true]) |
Enable translatable tabs for input. | |
Parameters:
Locales should be setted in controller's |
copy
|
|
min(float $min) |
Set min attribute.
|
|
Parameters:
|
copy
|
|
max(float $max) |
Set max attribute.
|
|
Parameters:
|
copy
|
|
step(float $step) |
Set step attribute.
|
|
Parameters:
|
copy
|
Radio
<input type="radio" />
field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
options(array $options) |
Set array of available options. | |
Parameters:
|
copy
For Select field
copy
|
|
columns(int $columns) |
By how many columns should options or relation values be divided.
|
|
Parameters:
|
copy
|
|
relation(string $method, string $titleField [, string $groupTitle = '']) |
Add relation dependency for field. | |
Parameters:
|
copy
copy
|
|
addCondition(\Closure $callback) |
Add clause for getting relation options. | |
Parameters:
|
copy
|
|
relationSearch(\Closure $callback) |
Define custom search callback for querying additional options with ajax enabled.
|
|
Parameters:
Default behavior:
`Select` field: works only for |
copy
|
Select
<select></select>
field.
Select::make('fruit')->relation('fruit', 'name');
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
type(string $type) |
Set field's type. | |
Parameters:
Wysiwyg
|
copy
copy
|
|
options(array $options) |
Set array of available options. | |
Parameters:
|
copy
For Select field
copy
|
|
relation(string $method, string $titleField [, string $groupTitle = '']) |
Add relation dependency for field. | |
Parameters:
|
copy
copy
|
|
addCondition(\Closure $callback) |
Add clause for getting relation options. | |
Parameters:
|
copy
|
|
relationSearch(\Closure $callback) |
Define custom search callback for querying additional options with ajax enabled.
|
|
Parameters:
Default behavior:
`Select` field: works only for |
copy
|
|
multiple([bool $multiple = true]) |
Flag field as multiple. | |
Parameters:
Attribute should be casted to array in model's
$cast if it's not relation field.
|
copy
|
|
ajax([bool ajax = true]) |
Enable ajax search for `Select` field with select2 type, or for `Tags` field.
|
|
Parameters:
`Select` field: works only for |
copy
|
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.
Tags::make('ips')->relation('ips', 'ip')->hideOptions();
Tags::make('phones');
Password
<input type="password" />
field.
Password::make('password');
Hidden
<input type="password" />
field.
Pass extra values to form handlers for validation rules or smth else.
Hidden::make('my_hidden_field')->default('hidden_field_value');
ColorPicker
Color picker plugin field for hex
and rgba
values.
ColorPicker::make('sektor', 'Sektor color');
ColorPicker::make('cyrax', 'Cyrax color')->type('rgba');
// or
ColorPicker::make('cyrax', 'Cyrax color')->type(ColorPicker::RGBA);
IconPicker
Icon picker plugin field for FontAwesome 4.7.0
value.
IconPicker::make('icon');
Markdown
Markdown text editor.
Markdown::make('content');
Wysiwyg
Summernote
wysiwyg editor.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
orderable([[bool $orderable = true [, \Closure $overridedOrderCallback = null]]) |
Add order button to field column. | |
Parameters:
|
copy
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
type(string $type) |
Set field's type. | |
Parameters:
Wysiwyg
|
copy
copy
|
|
translatable([bool $translatable = true]) |
Enable translatable tabs for input. | |
Parameters:
Locales should be setted in controller's |
copy
|
|
options(array $options) |
Set options for selected wysiwyg editor. | |
Parameters:
|
copy
copy
|
File
<input type="file" />
field.
File::make('pdf', 'Some pdf file')->disk('public');
Image
Widget field with ability to crop, preview image, rotate cropped image, and set background color for uncovered corners.
Image::make('background')->crop()->ratio(800, 300);
Date
Datepicker field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
placeholder($placeholder) |
Placeholder for field. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
inline([bool $enabled = true, array $options = []]) |
Enable inline edit in list view to change column's value. | |
Parameters:
Column will be validating under its rules in |
copy
copy
|
|
months(int $months) |
Set months count to be shown. | |
Parameters:
|
copy
|
|
format(string $momentJsFormat) |
Set date fromat. | |
Parameters:
|
copy
|
Datetime
Datetimepicker field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
readonly([bool $isReadonly = true]) |
Set field to readonly state. | |
Parameters:
|
copy
|
|
placeholder($placeholder) |
Placeholder for field. | |
Parameters:
|
copy
|
|
default($value) |
Field's default value. | |
Parameters:
|
copy
copy
|
|
nullable([bool $isNullable = true]) |
Make field nullable; false values will be converted to null. | |
Parameters:
|
copy
|
|
format(string $momentJsFormat) |
Set date fromat. | |
Parameters:
|
copy
|
Time
Time field.
Time::make('close_time');
Repeater
Repeater field.
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:
|
copy
|
|
title(string $title) |
Label of field. | |
Parameters:
|
copy
|
|
col(int $col) |
Set col size for <div> of field's input.
|
|
Parameters:
|
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
translatable([bool $translatable = true]) |
Enable translatable tabs for input. | |
Parameters:
Locales should be setted in controller's |
copy
|
|
width(int $width) |
Set width for field's column in list view of table. | |
Parameters:
|
copy
|
|
sortable([bool $enable = true) |
Enable sortable functionality for dragging repeater's items. | |
Parameters:
|
copy
|
|
fields([array $fields]) |
Add fields that should be rendered int repeater item. | |
Parameters:
|
copy
|
|
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:
|
copy
|
RowMarkup
Markup field for wrapping fields in <div class="row"></div>
.
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.
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:
$this->addFields([
Text::make('id')->readonly(),
'title',
'description',
]);
Or by one column:
$this->addField(Text::make('id')->readonly());
$this->addField('title');
Columns will be shown in table in order as they were specified.
Input Filters
TextFilter
Text::make('title')->filter(TextFilter::make());
TextareaFilter
Textarea::make('description')->filter(TextareaFilter::make());
NumberFilter
Number::make('price')->filter(NumberFilter::make());
SelectFilter
Select::make('posts')->relation('posts', 'title')->filter(SelectFilter::make());
DateFilter
Datetime::make('created_at')->filter(DateFilter::make()->range());
CheckboxFilter
Checkbox::make('is_active', 'Status')->filter(CheckboxFilter::make()->titles('Active', "Inactive', 'Any'));
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:
$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
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.
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:
$this->addAction(ShowAction::make());
Additionally you can specify it's position:
$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.
$this->addTool(new ShowHideColumnsTool());
2. \Yaro\Jarboe\Table\Toolbar\MassDeleteTool
enables checkboxes on each row and adds button for bulk deleting.
$this->addTool(new MassDeleteTool());
3. \Yaro\Jarboe\Table\Toolbar\MassRestoreTool
enables checkboxes on each row and adds button for bulk restoring.
$this->addTool(new MassRestoreTool());
How to make your own tool?
Helper functions
admin_url
Generates fully qualified admin url for passed path.
admin_url('users');
// http://localhost/admin/users
admin_user_guard
Returns admin's guard name.
admin_user_guard();
// admin
admin_user
Returns admin user object. Wrapper for auth(admin_user_guard())->user()
.
$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.
$idAdmin = admin_auth()->id();
urlify
Convert utf8 strings to ASCII strings which can be used as readable URL-segments.
$slug = urlify("Omelette à l'ancienne!");
// omelette-lancienne
Directives
pushonce
Works the same as push
directive, but with one small difference: pushed codeblock will be stacked only once.
@pushonce('scripts', <script src="/js/super.min.js"></script>)
@pushonce('styles', <style>
div > span {
color: mistyrose;
}
</style>)
Create custom field
In this example we'll make custom field to make slug from field's value that will be passed in request.
-
Create class for new field that extends from
Yaro\Jarboe\Table\Fields\AbstractField
. -
Define abstract methods for render purposes:
getListView
,getEditFormView
, andgetCreateFormView
; -
Define method
makeFrom
for setting field's name that should be slugged. -
Override
value
method for retrieving value that will be passed to model. There will be placed code for slugging string.
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,
]);
}
}
- Create views that will be rendered for this field for representing model's value.
{{-- resources/views/admin/fields/slug/list.blade.php --}}
{{ $field->getAttribute($model) }}
{{-- 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>
{{-- 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.
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:
-
Create class that extends
Yaro\Jarboe\Table\Actions\AbstractAction
. -
Define
render
method that is mandatory by interface for rendering button.
use Yaro\Jarboe\Table\Actions\AbstractAction;
class ShowPostAction extends AbstractAction
{
public function render($model = null)
{
return view('admin.actions.show_post', compact('model'));
}
}
-
Create view
resources/views/admin/actions/show_post.blade.php
;
<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.
public function init()
{
// ...
$this->addAction(ShowPostAction::make(), 'before', 'edit');
// ...
}