PHP code example of mariojgt / builder
1. Go to this page and download the library: Download mariojgt/builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mariojgt / builder example snippets
use Mariojgt\Builder\Controllers\TableBuilderApiController;
Route::controller(TableBuilderApiController::class)->group(function () {
Route::post('/admin/api/generic/table', 'index')
->name('admin.api.generic.table');
Route::post('/admin/api/generic/table/create', 'store')
->name('admin.api.generic.table.create');
Route::post('/admin/api/generic/table/update', 'update')
->name('admin.api.generic.table.update');
Route::post('/admin/api/generic/table/delete', 'delete')
->name('admin.api.generic.table.delete');
});
namespace Mariojgt\GameDev\Controllers\Backend;
use Inertia\Inertia;
use Mariojgt\GameDev\Models\Alert;
use App\Http\Controllers\Controller;
use Mariojgt\Builder\Enums\FieldTypes;
use Mariojgt\Builder\Helpers\FormHelper;
use Mariojgt\Builder\Enums\PermissionEnum;;
class AlertController extends Controller
{
public function index()
{
$breadcrumb = [
[
'label' => 'Alerts',
'url' => route('gamedev.alert.index'),
]
];
$form = new FormHelper();
$formConfig = $form
->addIdField()
// ->addIdField(label: 'product_id', key: 'product_id') // custom id field
->tab('General Info')
->addField(
label: 'Title',
key: 'title',
sortable: true,
type: FieldTypes::TEXT->value
)->withRules([ // You can pass laravel validation rules in the withRules method
'el: 'Icon',
key: 'icon',
sortable: false,
type: FieldTypes::SELECT->value,
options: [
'AlertTriangle' => 'Warning Triangle',
'AlertCircle' => 'Info Circle',
'AlertOctagon' => 'Error Octagon',
'Clock' => 'Clock',
'Bell' => 'Bell',
'Info' => 'Info'
],
)
->addField(
label: 'Theme',
key: 'theme',
sortable: true,
type: FieldTypes::SELECT->value,
options: [
'dark' => 'Dark Theme',
'light' => 'Light Theme'
],
)
->addField(
label: 'Button Text',
key: 'button_text',
sortable: false,
type: FieldTypes::TEXT->value,
)
->addField(
label: 'Button Icon',
key: 'button_icon',
sortable: false,
type: FieldTypes::SELECT->value,
options: [
'Eye' => 'Eye',
'Check' => 'Checkmark',
'X' => 'Close',
'ThumbsUp' => 'Thumbs Up'
],
)
->addField(
label: 'Enabled',
key: 'is_enabled',
sortable: true,
type: FieldTypes::BOOLEAN->value,
)
->addField(
label: 'Full Screen',
key: 'is_full_screen',
sortable: true,
type: FieldTypes::BOOLEAN->value,
)
->addField(
label: 'Scheduled At',
key: 'scheduled_at',
sortable: true,
canEdit: false,
type: FieldTypes::TIMESTAMP->value,
)
->addField(
label: 'Start At',
key: 'start_at',
sortable: true,
canEdit: false,
type: FieldTypes::TIMESTAMP->value,
)
->addField(
label: 'End At',
key: 'end_at',
sortable: true,
canEdit: false,
type: FieldTypes::TIMESTAMP->value,
)
->addField(
label: 'Dismissible',
key: 'is_dismissible',
sortable: true,
type: FieldTypes::BOOLEAN->value,
)
->addField(
label: 'Display Order',
key: 'display_order',
sortable: true,
type: FieldTypes::NUMBER->value,
)
->setEndpoints(
listEndpoint: route('admin.api.generic.table'),
deleteEndpoint: route('admin.api.generic.table.delete'),
createEndpoint: route('admin.api.generic.table.create'),
editEndpoint: route('admin.api.generic.table.update')
)
->setModel(Alert::class)
->setPermissions(
guard: 'skeleton_admin',
type: 'permission',
permissions: [
'store' => PermissionEnum::CreatePermission->value,
'update' => PermissionEnum::EditPermission->value,
'delete' => PermissionEnum::DeletePermission->value,
'index' => PermissionEnum::ReadPermission->value,
]
)
->build();
return Inertia::render('BackEnd/Vendor/GameDev/Generic/Index', [
'title' => 'Alerts | Index',
'table_name' => 'alerts',
'breadcrumb' => $breadcrumb,
...$formConfig
]);
}
}
// Table filters example
$form = new FormHelper();
$formConfig = $form
->addIdField()
->tab('General Info')
->addField(
label: 'Name',
key: 'name',
sortable: true,
canCreate: true,
canEdit: true,
type: FieldTypes::TEXT->value,
filterable: true // Enable filtering for this field
)
->addField(
label: 'Is Active',
key: 'is_active',
sortable: true,
type: FieldTypes::BOOLEAN->value,
canCreate: true,
canEdit: true,
filterable: true
)
->addField(
label: 'Created At',
key: 'created_at',
type: FieldTypes::DATE->value,
filterable: true,
filterOptions: ['type' => 'date-range']
)
->addField(
label: 'Status',
key: 'status',
type: FieldTypes::SELECT->value,
options: [
'select_options' => [
['value' => 'active', 'label' => 'Active'],
['value' => 'inactive', 'label' => 'Inactive'],
['value' => 'pending', 'label' => 'Pending']
]
],
filterable: true
)
// ... rest of your fields
bash
composer install::builder