mariojgt / builder
Laravel Crud 构建器,带有动态表格和 Vue.js 编写的控制器
1.1.2
2023-10-01 10:01 UTC
Requires
- php: ^8.0
README
Builder
介绍我们的 Laravel 包,这是在项目中快速构建通用 CRUD 操作的完美解决方案。只需几个简单的命令,您就可以轻松生成创建、读取、更新和删除数据库中数据的样板代码。我们的包设计灵活且可定制,可轻松调整以适应您项目的特定要求。告别繁琐的手动编码,用我们强大且直观的包节省宝贵的时间。
功能
- 集成 Laravel 的可用的数据库 CRUD API。
- 动态表单构建器。
要求
- Laravel。
- Tailwind。
- Daisy ui。
- Inersia js。
通过 composer 选择第一个选项
- composer require mariojgt/builder
- php artisan install::builder
这将复制资源资产、运行迁移并复制一些我们需要使用的配置文件;
如何使用
1: 前往路由文件,首先需要添加以下行
// Table api controller in where you can use your middleware 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'); });
2: 在您的控制器中需要以下数组
// Table columns $columns = [ [ 'label' => 'Id', // Display name 'key' => 'id', // Table column key 'sortable' => true, // Can be use in the filter 'canCreate' => false, // Can be use in the create form 'canEdit' => false, // Can be use in the edit form ], [ 'label' => 'Name', // Display name 'key' => 'name', // Table column key 'sortable' => true, // Can be use in the filter 'canCreate' => true, // Can be use in the create form 'canEdit' => true, // Can be use in the edit form 'type' => 'text', // Type text,email,password,date,timestamp ], [ 'label' => 'Guard', 'key' => 'guard_name', 'sortable' => true, 'canCreate' => true, 'canEdit' => true, 'type' => 'text', ], [ 'label' => 'Created At', 'key' => 'created_at', 'sortable' => false, 'canCreate' => false, 'canEdit' => true, 'type' => 'date', ], [ 'label' => 'Updated At', 'key' => 'updated_at', 'sortable' => false, 'canCreate' => false, 'canEdit' => true, 'type' => 'timestamp', ], ]; return Inertia::render('BackEnd/Role/Index', [ 'title' => 'Role | Roles', // Required for the Builder Generic table api 'endpoint' => route('admin.api.generic.table'), 'endpointDelete' => route('admin.api.generic.table.delete'), 'endpointCreate' => route('admin.api.generic.table.create'), 'endpointEdit' => route('admin.api.generic.table.update'), // You table columns 'columns' => $columns, // The model where all those actions will take place 'model' => encrypt(Role::class), // If you want to protect your crud form you can use this below not required 'permission' => encrypt([ // Must be encrypted 'guard' => 'skeleton_admin', // You can use permission or role up to you 'type' => 'permission', // The permission name or role 'key' => [ 'store' => 'create-permission', 'update' => 'edit-permission', 'delete' => 'delete-permission', 'index' => 'read-permission', ], ]), ]);
