Skip to content

Instantly share code, notes, and snippets.

@tabacitu
Created October 25, 2018 09:13
Show Gist options
  • Save tabacitu/016e3cc90be06950b9bcea37dec3e69d to your computer and use it in GitHub Desktop.
Save tabacitu/016e3cc90be06950b9bcea37dec3e69d to your computer and use it in GitHub Desktop.
Proposal MonsterCrudConfiguration files
<?php
namespace App\AdminPanel\Configurations;
use Illuminate\Http\Request;
class MonsterCrudConfiguration {
public static $model = 'App\Models\Monster';
public static $entityNameSingular = 'monster';
public static $entityNamePlural = 'monsters';
public static $enabledOperations = [
'create', 'update', 'listEntries', 'show', 'delete'
];
public static $settings = [
'listEntries.detailsRow' => true,
'listEntries.detailsRow.view' => 'vendor.backpack.crud.details_row.monster',
'listEntries.exportButtons' => true,
'listEntries.bulkActions' => true,
'listEntries.search.additionalColumns' => ['wysiwyg'],
'listEntries.pagination.defaultPageLength' => 10,
'listEntries.responsive' => false,
];
public static $defaultTextAttribute = 'text';
public static $defaultImageAttribute = false;
public function route(Request $request) {
return config('backpack.base.route_prefix').'/monster';
}
public function columns(Request $request)
{
return [
'text',
'textarea',
'select', // Backpack will know how to show this because the same attribute is explicitly configured as a field
[
'name' => 'upload_multiple', // The db column name
'label' => "Upload multiple", // Table column heading
'type' => 'array_count',
'suffix' => ' files',
],
];
}
public function filters(Request $request)
{
return [
[[ // add a "simple" filter called Draft
'type' => 'simple',
'name' => 'checkbox',
'label' => 'Simple',
],
false, // the simple filter has no values, just the "Draft" label specified above
function () { // if the filter is active (the GET parameter "draft" exits)
$this->crud->addClause('where', 'checkbox', '1');
}],
[[ // dropdown filter
'name' => 'select_from_array',
'type' => 'dropdown',
'label'=> 'Dropdown',
], ['one' => 'One', 'two' => 'Two', 'three' => 'Three'], function ($value) {
// if the filter is active
$this->crud->addClause('where', 'select_from_array', $value);
}],
[[ // text filter
'type' => 'text',
'name' => 'text',
'label' => 'Text',
],
false,
function ($value) { // if the filter is active
$this->crud->addClause('where', 'text', 'LIKE', "%$value%");
}],
[[
'name' => 'number',
'type' => 'range',
'label' => 'Range',
'label_from' => 'min value',
'label_to' => 'max value',
],
false,
function ($value) { // if the filter is active
$range = json_decode($value);
if ($range->from && $range->to) {
$this->crud->addClause('where', 'number', '>=', (float) $range->from);
$this->crud->addClause('where', 'number', '<=', (float) $range->to);
}
}],
[[ // date filter
'type' => 'date',
'name' => 'date',
'label' => 'Date',
],
false,
function ($value) { // if the filter is active, apply these constraints
$this->crud->addClause('where', 'date', '=', $value);
}],
[[ // daterange filter
'type' => 'date_range',
'name' => 'date_range',
'label'=> 'Date range',
// 'date_range_options' => [
// 'format' => 'YYYY/MM/DD',
// 'locale' => ['format' => 'YYYY/MM/DD'],
// 'showDropdowns' => true,
// 'showWeekNumbers' => true
// ]
],
false,
function ($value) { // if the filter is active, apply these constraints
$dates = json_decode($value);
$this->crud->addClause('where', 'date', '>=', $dates->from);
$this->crud->addClause('where', 'date', '<=', $dates->to);
}],
[[ // select2 filter
'name' => 'select2',
'type' => 'select2',
'label'=> 'Select2',
], function () {
return \Backpack\NewsCRUD\app\Models\Category::all()->keyBy('id')->pluck('name', 'id')->toArray();
}, function ($value) { // if the filter is active
$this->crud->addClause('where', 'select2', $value);
}],
[[ // select2_multiple filter
'name' => 'select2_multiple',
'type' => 'select2_multiple',
'label'=> 'Select2 multiple',
], function () {
return \Backpack\NewsCRUD\app\Models\Category::all()->keyBy('id')->pluck('name', 'id')->toArray();
}, function ($values) { // if the filter is active
foreach (json_decode($values) as $key => $value) {
$this->crud->addClause('orWhere', 'select2', $value);
}
}],
[[ // select2_ajax filter
'name' => 'select2_from_ajax',
'type' => 'select2_ajax',
'label' => 'Select2 Ajax',
'placeholder' => 'Pick an article',
],
url('api/article-search'), // the ajax route
function ($value) { // if the filter is active
$this->crud->addClause('where', 'select2_from_ajax', $value);
}],
];
}
public function buttons(Request $request)
{
return [
// default buttons
['line', 'show', 'view', 'crud::buttons.show', 'end'],
['line', 'update', 'view', 'crud::buttons.update', 'end'],
['line', 'revisions', 'view', 'crud::buttons.revisions', 'end'],
['line', 'delete', 'view', 'crud::buttons.delete', 'end'],
['top', 'create', 'view', 'crud::buttons.create'],
['top', 'reorder', 'view', 'crud::buttons.reorder'],
// custom buttons
['line', 'clone', 'view', 'crud::buttons.clone', 'beginning'],
['bottom', 'bulk_clone', 'view', 'crud::buttons.bulk_clone', 'end'],
];
}
public function fields(Request $request)
{
// return a single array if the fields are the same for all operations
// return ['create' => [..], 'update' => [..]] if you want different fields on each operation
return [
[
'name' => 'text',
'label' => 'Text',
'type' => 'text',
'tab' => 'Simple',
],
[
'name' => 'email',
'label' => 'Email',
'type' => 'email',
'tab' => 'Simple',
],
[ // Textarea
'name' => 'textarea',
'label' => 'Textarea',
'type' => 'textarea',
'tab' => 'Simple',
],
[ // Number
'name' => 'number',
'label' => 'Number',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
// 'prefix' => "$",
// 'suffix' => ".00",
'tab' => 'Simple',
],
[ // Number
'name' => 'float',
'label' => 'Float',
'type' => 'number',
// optionals
'attributes' => ['step' => 'any'], // allow decimals
// 'prefix' => "$",
// 'suffix' => ".00",
'tab' => 'Simple',
],
[ // Number
'name' => 'number_with_prefix',
'label' => 'Number with prefix',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
'prefix' => '$',
// 'suffix' => ".00",
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Number
'name' => 'number_with_suffix',
'label' => 'Number with suffix',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
// 'prefix' => "$",
'suffix' => '.00',
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Number
'name' => 'text_with_both_prefix_and_suffix',
'label' => 'Text with both prefix and suffix',
'type' => 'number',
'prefix' => '@',
'suffix' => "<i class='fa fa-home'></i>",
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Password
'name' => 'password',
'label' => 'Password',
'type' => 'password',
'tab' => 'Simple',
],
[
'name' => 'radio', // the name of the db column
'label' => 'Status (radio)', // the input label
'type' => 'radio',
'options' => [ // the key will be stored in the db, the value will be shown as label;
0 => 'Draft',
1 => 'Published',
2 => 'Other',
],
// optional
'inline' => true, // show the radios all on the same line?
'tab' => 'Simple',
],
[ // Checkbox
'name' => 'checkbox',
'label' => 'I have not read the terms and conditions and I never will (checkbox)',
'type' => 'checkbox',
'tab' => 'Simple',
],
[ // Hidden
'name' => 'hidden',
'type' => 'hidden',
'default' => 'hidden value',
'tab' => 'Simple',
],
// -----------------
// DATE, TIME AND SPACE tab
// -----------------
[ // Month
'name' => 'week',
'label' => 'Week',
'type' => 'week',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Month
'name' => 'month',
'label' => 'Month',
'type' => 'month',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date
'name' => 'date',
'label' => 'Date (HTML5 spec)',
'type' => 'date',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date
'name' => 'date_picker',
'label' => 'Date (jQuery plugin)',
'type' => 'date_picker',
// optional:
'date_picker_options' => [
'todayBtn' => true,
'format' => 'dd-mm-yyyy',
'language' => 'en',
],
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // DateTime
'name' => 'datetime',
'label' => 'Datetime (HTML5 spec)',
'type' => 'datetime',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // DateTime
'name' => 'datetime_picker',
'label' => 'Datetime picker (jQuery plugin)',
'type' => 'datetime_picker',
// optional:
'datetime_picker_options' => [
'format' => 'DD/MM/YYYY HH:mm',
'language' => 'en',
],
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date_range
'name' => 'date_range', // a unique name for this field
'start_name' => 'start_date', // the db column that holds the start_date
'end_name' => 'end_date', // the db column that holds the end_date
'label' => 'Date Range',
'type' => 'date_range',
// OPTIONALS
'start_default' => '2017-03-28 01:01', // default value for start_date
'end_default' => '2017-04-05 02:00', // default value for end_date
'date_range_options' => [ // options sent to daterangepicker.js
'timePicker' => true,
'locale' => ['format' => 'DD/MM/YYYY HH:mm'],
],
'tab' => 'Time and space',
],
[ // Address
'name' => 'address',
'label' => 'Address (Algolia Places search)',
'type' => 'address',
// optional
'store_as_json' => true,
'tab' => 'Time and space',
'operations' => ['create', 'update'],
], // the second parameter for the addField method is the form it should place this field in; specify either 'create', 'update' or 'both'; default is 'both', so you might aswell not mention it;
// -----------------
// SELECTS tab
// -----------------
[ // SELECT
'label' => 'Select (1-n relationship)',
'type' => 'select',
'name' => 'select',
'entity' => 'category',
'attribute' => 'name',
'model' => "Backpack\NewsCRUD\app\Models\Category",
'tab' => 'Selects',
// 'default' => '802',
],
[ // Select_Multiple = n-n relationship
'label' => 'Select_multiple (n-n relationship with pivot table)',
'type' => 'select_multiple',
'name' => 'tags', // the method that defines the relationship in your Model
'entity' => 'tags', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Tag", // foreign key model
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
[ // select_from_array
'name' => 'select_from_array',
'label' => 'Select_from_array (no relationship, 1-1 or 1-n)',
'type' => 'select_from_array',
'options' => ['one' => 'One', 'two' => 'Two', 'three' => 'Three'],
'allows_null' => true,
'tab' => 'Selects',
'allows_multiple' => false, // OPTIONAL; needs you to cast this to array in your model;
],
[ // SELECT2
'label' => 'Select2 (1-n relationship)',
'type' => 'select2',
'name' => 'select2',
'entity' => 'category',
'attribute' => 'name',
'model' => "Backpack\NewsCRUD\app\Models\Category",
'tab' => 'Selects',
],
[ // Select2Multiple = n-n relationship (with pivot table)
'label' => 'Select2_multiple (n-n relationship with pivot table)',
'type' => 'select2_multiple',
'name' => 'categories', // the method that defines the relationship in your Model
'entity' => 'categories', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Category", // foreign key model
'allows_null' => true,
'select_all' => true,
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
[ // select2_from_array
'name' => 'select2_from_array',
'label' => 'Select2_from_array (no relationship, 1-1 or 1-n)',
'type' => 'select2_from_array',
'options' => ['one' => 'One', 'two' => 'Two', 'three' => 'Three'],
'allows_null' => true,
'tab' => 'Selects',
'allows_multiple' => false, // OPTIONAL; needs you to cast this to array in your model;
],
[ // select2_from_ajax: 1-n relationship
'label' => "Article <small class='font-light'>(select2_from_ajax for a 1-n relationship)</small>", // Table column heading
'type' => 'select2_from_ajax',
'name' => 'select2_from_ajax', // the column that contains the ID of that connected entity;
'entity' => 'article', // the method that defines the relationship in your Model
'attribute' => 'title', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Article", // foreign key model
'data_source' => url('api/article'), // url to controller search function (with /{id} should return model)
'placeholder' => 'Select an article', // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'tab' => 'Selects',
],
[ // Select2_from_ajax_multiple: n-n relationship with pivot table
'label' => "Articles <small class='font-light'>(select2_from_ajax_multiple for an n-n relationship with pivot table)</small>", // Table column heading
'type' => 'select2_from_ajax_multiple',
'name' => 'articles', // the column that contains the ID of that connected entity;
'entity' => 'articles', // the method that defines the relationship in your Model
'attribute' => 'title', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Article", // foreign key model
'data_source' => url('api/article'), // url to controller search function (with /{id} should return model)
'placeholder' => 'Select one or more articles', // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
// -----------------
// UPLOADS tab
// -----------------
[ // Browse
'name' => 'browse',
'label' => 'Browse (using elFinder)',
'type' => 'browse',
'tab' => 'Uploads',
],
[ // base64_image
'label' => 'Base64 Image - includes cropping',
'name' => 'base64_image',
'filename' => null, // set to null if not needed
'type' => 'base64_image',
'aspect_ratio' => 1, // set to 0 to allow any aspect ratio
'crop' => true, // set to true to allow cropping, false to disable
'src' => null, // null to read straight from DB, otherwise set to model accessor function
'tab' => 'Uploads',
],
// $table->string('image')->nullable;
// $table->string('upload')->nullable;
// $table->string('upload_multiple')->nullable;
[ // Upload
'name' => 'upload_multiple',
'label' => 'Upload multiple',
'type' => 'upload_multiple',
'upload' => true,
'disk' => 'uploads', // if you store files in the /public folder, please ommit this; if you store them in /storage or S3, please specify it;
'tab' => 'Uploads',
],
// -----------------
// BIG TEXTS tab
// -----------------
[ // SimpleMDE
'name' => 'simplemde',
'label' => 'SimpleMDE - markdown editor',
'type' => 'simplemde',
'tab' => 'Big texts',
],
[ // Summernote
'name' => 'summernote',
'label' => 'Summernote editor',
'type' => 'summernote',
'tab' => 'Big texts',
],
[ // CKEditor
'name' => 'wysiwyg',
'label' => 'CKEditor - also called the WYSIWYG field',
'type' => 'ckeditor',
'tab' => 'Big texts',
],
[ // TinyMCE
'name' => 'tinymce',
'label' => 'TinyMCE',
'type' => 'tinymce',
'tab' => 'Big texts',
],
// -----------------
// MISCELLANEOUS tab
// -----------------
[ // Color
'name' => 'color',
'label' => 'Color picker (HTML5 spec)',
'type' => 'color',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Miscellaneous',
],
[ // Color
'name' => 'color_picker',
'label' => 'Color picker (jQuery plugin)',
'type' => 'color_picker',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Miscellaneous',
],
[
'label' => 'Icon Picker',
'name' => 'icon_picker',
'type' => 'icon_picker',
'iconset' => 'fontawesome', // options: fontawesome, glyphicon, ionicon, weathericon, mapicon, octicon, typicon, elusiveicon, materialdesign
'tab' => 'Miscellaneous',
],
[ // Table
'name' => 'table',
'label' => 'Table',
'type' => 'table',
'entity_singular' => 'subentry', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'desc' => 'Description',
'price' => 'Price',
],
'max' => 5, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => 'Miscellaneous',
],
[ // Table
'name' => 'fake_table',
'label' => 'Fake Table',
'type' => 'table',
'entity_singular' => 'subentry', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'desc' => 'Description',
'price' => 'Price',
],
'fake' => true,
'max' => 5, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => 'Miscellaneous',
],
];
}
public function validation(Request $request)
{
// array of operation => FormRequest class
// or
// array of operation => array of rules
return [
'create' => 'App\Http\Requests\MonsterRequest',
'edit' => 'App\Http\Requests\MonsterRequest',
];
}
}
<?php
namespace App\AdminPanel\Configurations;
use Illuminate\Http\Request;
class MonsterCrudConfiguration {
public static $model = 'App\Models\Monster';
public static $entityNameSingular = 'monster';
public static $entityNamePlural = 'monsters';
public static $enabledOperations = [
'create', 'update', 'listEntries', 'show', 'delete'
];
public static $defaultTextAttribute = 'text';
public static $defaultImageAttribute = false;
public function route(Request $request) {
return config('backpack.base.route_prefix').'/monster';
}
public function listEntries(Request $request)
{
$columns = [
'text',
'textarea',
'select', // Backpack will know how to show this because the same attribute is explicitly configured as a field
[
'name' => 'upload_multiple', // The db column name
'label' => "Upload multiple", // Table column heading
'type' => 'array_count',
'suffix' => ' files',
],
];
$buttons = [
// default buttons
['line', 'show', 'view', 'crud::buttons.show', 'end'],
['line', 'update', 'view', 'crud::buttons.update', 'end'],
['line', 'revisions', 'view', 'crud::buttons.revisions', 'end'],
['line', 'delete', 'view', 'crud::buttons.delete', 'end'],
['top', 'create', 'view', 'crud::buttons.create'],
['top', 'reorder', 'view', 'crud::buttons.reorder'],
// custom buttons
['line', 'clone', 'view', 'crud::buttons.clone', 'beginning'],
['bottom', 'bulk_clone', 'view', 'crud::buttons.bulk_clone', 'end'],
];
$filters = [
[[ // add a "simple" filter called Draft
'type' => 'simple',
'name' => 'checkbox',
'label' => 'Simple',
],
false, // the simple filter has no values, just the "Draft" label specified above
function () { // if the filter is active (the GET parameter "draft" exits)
$this->crud->addClause('where', 'checkbox', '1');
}],
[[ // dropdown filter
'name' => 'select_from_array',
'type' => 'dropdown',
'label'=> 'Dropdown',
], ['one' => 'One', 'two' => 'Two', 'three' => 'Three'], function ($value) {
// if the filter is active
$this->crud->addClause('where', 'select_from_array', $value);
}],
[[ // text filter
'type' => 'text',
'name' => 'text',
'label' => 'Text',
],
false,
function ($value) { // if the filter is active
$this->crud->addClause('where', 'text', 'LIKE', "%$value%");
}],
[[
'name' => 'number',
'type' => 'range',
'label' => 'Range',
'label_from' => 'min value',
'label_to' => 'max value',
],
false,
function ($value) { // if the filter is active
$range = json_decode($value);
if ($range->from && $range->to) {
$this->crud->addClause('where', 'number', '>=', (float) $range->from);
$this->crud->addClause('where', 'number', '<=', (float) $range->to);
}
}],
[[ // date filter
'type' => 'date',
'name' => 'date',
'label' => 'Date',
],
false,
function ($value) { // if the filter is active, apply these constraints
$this->crud->addClause('where', 'date', '=', $value);
}],
[[ // daterange filter
'type' => 'date_range',
'name' => 'date_range',
'label'=> 'Date range',
// 'date_range_options' => [
// 'format' => 'YYYY/MM/DD',
// 'locale' => ['format' => 'YYYY/MM/DD'],
// 'showDropdowns' => true,
// 'showWeekNumbers' => true
// ]
],
false,
function ($value) { // if the filter is active, apply these constraints
$dates = json_decode($value);
$this->crud->addClause('where', 'date', '>=', $dates->from);
$this->crud->addClause('where', 'date', '<=', $dates->to);
}],
[[ // select2 filter
'name' => 'select2',
'type' => 'select2',
'label'=> 'Select2',
], function () {
return \Backpack\NewsCRUD\app\Models\Category::all()->keyBy('id')->pluck('name', 'id')->toArray();
}, function ($value) { // if the filter is active
$this->crud->addClause('where', 'select2', $value);
}],
[[ // select2_multiple filter
'name' => 'select2_multiple',
'type' => 'select2_multiple',
'label'=> 'Select2 multiple',
], function () {
return \Backpack\NewsCRUD\app\Models\Category::all()->keyBy('id')->pluck('name', 'id')->toArray();
}, function ($values) { // if the filter is active
foreach (json_decode($values) as $key => $value) {
$this->crud->addClause('orWhere', 'select2', $value);
}
}],
[[ // select2_ajax filter
'name' => 'select2_from_ajax',
'type' => 'select2_ajax',
'label' => 'Select2 Ajax',
'placeholder' => 'Pick an article',
],
url('api/article-search'), // the ajax route
function ($value) { // if the filter is active
$this->crud->addClause('where', 'select2_from_ajax', $value);
}],
];
return [
'columns' => $columns,
'buttons' => $buttons,
'filters' => $filters,
'settings' => [
'detailsRow' => true,
'detailsRow.view' => 'vendor.backpack.crud.details_row.monster',
'exportButtons' => true,
'bulkActions' => true,
'search.additionalColumns' => ['wysiwyg'],
'pagination.defaultPageLength' => 10,
'responsive' => false,
],
];
}
public function create(Request $request) {
$fields = [
[
'name' => 'text',
'label' => 'Text',
'type' => 'text',
'tab' => 'Simple',
],
[
'name' => 'email',
'label' => 'Email',
'type' => 'email',
'tab' => 'Simple',
],
[ // Textarea
'name' => 'textarea',
'label' => 'Textarea',
'type' => 'textarea',
'tab' => 'Simple',
],
[ // Number
'name' => 'number',
'label' => 'Number',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
// 'prefix' => "$",
// 'suffix' => ".00",
'tab' => 'Simple',
],
[ // Number
'name' => 'float',
'label' => 'Float',
'type' => 'number',
// optionals
'attributes' => ['step' => 'any'], // allow decimals
// 'prefix' => "$",
// 'suffix' => ".00",
'tab' => 'Simple',
],
[ // Number
'name' => 'number_with_prefix',
'label' => 'Number with prefix',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
'prefix' => '$',
// 'suffix' => ".00",
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Number
'name' => 'number_with_suffix',
'label' => 'Number with suffix',
'type' => 'number',
// optionals
// 'attributes' => ["step" => "any"], // allow decimals
// 'prefix' => "$",
'suffix' => '.00',
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Number
'name' => 'text_with_both_prefix_and_suffix',
'label' => 'Text with both prefix and suffix',
'type' => 'number',
'prefix' => '@',
'suffix' => "<i class='fa fa-home'></i>",
'fake' => true,
'store_in' => 'extras',
'tab' => 'Simple',
],
[ // Password
'name' => 'password',
'label' => 'Password',
'type' => 'password',
'tab' => 'Simple',
],
[
'name' => 'radio', // the name of the db column
'label' => 'Status (radio)', // the input label
'type' => 'radio',
'options' => [ // the key will be stored in the db, the value will be shown as label;
0 => 'Draft',
1 => 'Published',
2 => 'Other',
],
// optional
'inline' => true, // show the radios all on the same line?
'tab' => 'Simple',
],
[ // Checkbox
'name' => 'checkbox',
'label' => 'I have not read the terms and conditions and I never will (checkbox)',
'type' => 'checkbox',
'tab' => 'Simple',
],
[ // Hidden
'name' => 'hidden',
'type' => 'hidden',
'default' => 'hidden value',
'tab' => 'Simple',
],
// -----------------
// DATE, TIME AND SPACE tab
// -----------------
[ // Month
'name' => 'week',
'label' => 'Week',
'type' => 'week',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Month
'name' => 'month',
'label' => 'Month',
'type' => 'month',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date
'name' => 'date',
'label' => 'Date (HTML5 spec)',
'type' => 'date',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date
'name' => 'date_picker',
'label' => 'Date (jQuery plugin)',
'type' => 'date_picker',
// optional:
'date_picker_options' => [
'todayBtn' => true,
'format' => 'dd-mm-yyyy',
'language' => 'en',
],
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // DateTime
'name' => 'datetime',
'label' => 'Datetime (HTML5 spec)',
'type' => 'datetime',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // DateTime
'name' => 'datetime_picker',
'label' => 'Datetime picker (jQuery plugin)',
'type' => 'datetime_picker',
// optional:
'datetime_picker_options' => [
'format' => 'DD/MM/YYYY HH:mm',
'language' => 'en',
],
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Time and space',
],
[ // Date_range
'name' => 'date_range', // a unique name for this field
'start_name' => 'start_date', // the db column that holds the start_date
'end_name' => 'end_date', // the db column that holds the end_date
'label' => 'Date Range',
'type' => 'date_range',
// OPTIONALS
'start_default' => '2017-03-28 01:01', // default value for start_date
'end_default' => '2017-04-05 02:00', // default value for end_date
'date_range_options' => [ // options sent to daterangepicker.js
'timePicker' => true,
'locale' => ['format' => 'DD/MM/YYYY HH:mm'],
],
'tab' => 'Time and space',
],
[ // Address
'name' => 'address',
'label' => 'Address (Algolia Places search)',
'type' => 'address',
// optional
'store_as_json' => true,
'tab' => 'Time and space',
'operations' => ['create', 'update'],
], // the second parameter for the addField method is the form it should place this field in; specify either 'create', 'update' or 'both'; default is 'both', so you might aswell not mention it;
// -----------------
// SELECTS tab
// -----------------
[ // SELECT
'label' => 'Select (1-n relationship)',
'type' => 'select',
'name' => 'select',
'entity' => 'category',
'attribute' => 'name',
'model' => "Backpack\NewsCRUD\app\Models\Category",
'tab' => 'Selects',
// 'default' => '802',
],
[ // Select_Multiple = n-n relationship
'label' => 'Select_multiple (n-n relationship with pivot table)',
'type' => 'select_multiple',
'name' => 'tags', // the method that defines the relationship in your Model
'entity' => 'tags', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Tag", // foreign key model
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
[ // select_from_array
'name' => 'select_from_array',
'label' => 'Select_from_array (no relationship, 1-1 or 1-n)',
'type' => 'select_from_array',
'options' => ['one' => 'One', 'two' => 'Two', 'three' => 'Three'],
'allows_null' => true,
'tab' => 'Selects',
'allows_multiple' => false, // OPTIONAL; needs you to cast this to array in your model;
],
[ // SELECT2
'label' => 'Select2 (1-n relationship)',
'type' => 'select2',
'name' => 'select2',
'entity' => 'category',
'attribute' => 'name',
'model' => "Backpack\NewsCRUD\app\Models\Category",
'tab' => 'Selects',
],
[ // Select2Multiple = n-n relationship (with pivot table)
'label' => 'Select2_multiple (n-n relationship with pivot table)',
'type' => 'select2_multiple',
'name' => 'categories', // the method that defines the relationship in your Model
'entity' => 'categories', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Category", // foreign key model
'allows_null' => true,
'select_all' => true,
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
[ // select2_from_array
'name' => 'select2_from_array',
'label' => 'Select2_from_array (no relationship, 1-1 or 1-n)',
'type' => 'select2_from_array',
'options' => ['one' => 'One', 'two' => 'Two', 'three' => 'Three'],
'allows_null' => true,
'tab' => 'Selects',
'allows_multiple' => false, // OPTIONAL; needs you to cast this to array in your model;
],
[ // select2_from_ajax: 1-n relationship
'label' => "Article <small class='font-light'>(select2_from_ajax for a 1-n relationship)</small>", // Table column heading
'type' => 'select2_from_ajax',
'name' => 'select2_from_ajax', // the column that contains the ID of that connected entity;
'entity' => 'article', // the method that defines the relationship in your Model
'attribute' => 'title', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Article", // foreign key model
'data_source' => url('api/article'), // url to controller search function (with /{id} should return model)
'placeholder' => 'Select an article', // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'tab' => 'Selects',
],
[ // Select2_from_ajax_multiple: n-n relationship with pivot table
'label' => "Articles <small class='font-light'>(select2_from_ajax_multiple for an n-n relationship with pivot table)</small>", // Table column heading
'type' => 'select2_from_ajax_multiple',
'name' => 'articles', // the column that contains the ID of that connected entity;
'entity' => 'articles', // the method that defines the relationship in your Model
'attribute' => 'title', // foreign key attribute that is shown to user
'model' => "Backpack\NewsCRUD\app\Models\Article", // foreign key model
'data_source' => url('api/article'), // url to controller search function (with /{id} should return model)
'placeholder' => 'Select one or more articles', // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
'tab' => 'Selects',
],
// -----------------
// UPLOADS tab
// -----------------
[ // Browse
'name' => 'browse',
'label' => 'Browse (using elFinder)',
'type' => 'browse',
'tab' => 'Uploads',
],
[ // base64_image
'label' => 'Base64 Image - includes cropping',
'name' => 'base64_image',
'filename' => null, // set to null if not needed
'type' => 'base64_image',
'aspect_ratio' => 1, // set to 0 to allow any aspect ratio
'crop' => true, // set to true to allow cropping, false to disable
'src' => null, // null to read straight from DB, otherwise set to model accessor function
'tab' => 'Uploads',
],
// $table->string('image')->nullable;
// $table->string('upload')->nullable;
// $table->string('upload_multiple')->nullable;
[ // Upload
'name' => 'upload_multiple',
'label' => 'Upload multiple',
'type' => 'upload_multiple',
'upload' => true,
'disk' => 'uploads', // if you store files in the /public folder, please ommit this; if you store them in /storage or S3, please specify it;
'tab' => 'Uploads',
],
// -----------------
// BIG TEXTS tab
// -----------------
[ // SimpleMDE
'name' => 'simplemde',
'label' => 'SimpleMDE - markdown editor',
'type' => 'simplemde',
'tab' => 'Big texts',
],
[ // Summernote
'name' => 'summernote',
'label' => 'Summernote editor',
'type' => 'summernote',
'tab' => 'Big texts',
],
[ // CKEditor
'name' => 'wysiwyg',
'label' => 'CKEditor - also called the WYSIWYG field',
'type' => 'ckeditor',
'tab' => 'Big texts',
],
[ // TinyMCE
'name' => 'tinymce',
'label' => 'TinyMCE',
'type' => 'tinymce',
'tab' => 'Big texts',
],
// -----------------
// MISCELLANEOUS tab
// -----------------
[ // Color
'name' => 'color',
'label' => 'Color picker (HTML5 spec)',
'type' => 'color',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Miscellaneous',
],
[ // Color
'name' => 'color_picker',
'label' => 'Color picker (jQuery plugin)',
'type' => 'color_picker',
// 'wrapperAttributes' => ['class' => 'col-md-6'],
'tab' => 'Miscellaneous',
],
[
'label' => 'Icon Picker',
'name' => 'icon_picker',
'type' => 'icon_picker',
'iconset' => 'fontawesome', // options: fontawesome, glyphicon, ionicon, weathericon, mapicon, octicon, typicon, elusiveicon, materialdesign
'tab' => 'Miscellaneous',
],
[ // Table
'name' => 'table',
'label' => 'Table',
'type' => 'table',
'entity_singular' => 'subentry', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'desc' => 'Description',
'price' => 'Price',
],
'max' => 5, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => 'Miscellaneous',
],
[ // Table
'name' => 'fake_table',
'label' => 'Fake Table',
'type' => 'table',
'entity_singular' => 'subentry', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'desc' => 'Description',
'price' => 'Price',
],
'fake' => true,
'max' => 5, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => 'Miscellaneous',
],
];
return [
'fields' => $fields,
'validation' => 'App\Http\Requests\MonsterRequest',
];
}
public function edit(Request $request) {
$fields = $this->create($request)['fields'];
return [
'fields' => $fields,
'validation' => 'App\Http\Requests\MonsterRequest',
];
}
public function show(Request $request) {
$fields = $this->edit($request)['fields'];
return [
'fields' => $fields,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment