biswadeep/form-tool
Composer 安装命令:
composer require biswadeep/form-tool
包简介
A lightweight Laravel form tool to create your admin panel or web app easily!
README 文档
README
A lightweight Laravel form tool to create your web app or admin panel easily!
Create complex CRUDs easily and save time. Create bug-free and deliver confidently.
I love examples, let's get into it directly:
$model = new DataModel();
$model->db('products', 'productId');
$this->crud = Doc::create($this, $model, function (BluePrint $input) {
$input->text('productName', 'Product Name')->required();
$input->select('categoryId', 'Category')->options('categories.categoryId.categoryName')->required();
$input->number('price', 'Price')->required();
$input->image('image', 'Image');
$input->editor('description', 'Description');
});
Let me explain
Let's assume we have a database with a product table named products and with columns productId, productName, categoryId, price, image, description. And we have category table named categories with columns categoryId, categoryName
First, we have created a $model = new DataModel(); and on the 2nd line we have passed the table name and primary id of the product table. This is the simple way we tell the form tool that this is our CRUD table.
Then we create a CRUD by calling Doc::create() and the parameters are:
- The Laravel's controller class as $this
- Passing the $model we created above
- And the last parameter is the Closure which will provide us with a BluePrint as parameter.
Now let's understand our fields inside the Closure. For that let me tell you one thing for the most methods inside closure have 1st parameter as the database column name and 2nd as an optional label of that field. So here are the input fields:
- We have created a text field with the column
productNameand labelled asProduct Nameand applied the required validation. - Then a dropdown with the column
categoryIdand labelled asCategoryinstructing form tool to get the options from another tablecategoriesand thencategoryId&categoryNameseparated by dots(.) to show as value and text of the <option> tag respectively i.e. <option value="categoryId">categoryName</option>. Finally, we have added the required validation. - Then we have a price field with automatic digit validation as we have specified that it's a number field and then applied the required.
- Then we have created an image field which will automatically apply validation for the image file and upload the image under the sub-directory
public/storage/. More on the file uploading later. - And at last, we have created an editor by default
CKEditorfor our description column.
Full Code:
<?php
namespace App\Http\Controllers\Admin;
use Deep\FormTool\Core\Doc;
use Deep\FormTool\Core\BluePrint;
use Deep\FormTool\Core\DataModel;
class ProductsController extends AdminController
{
// Required for FormTool
public $title = 'Products';
public $route = 'products';
public $singularTitle = 'Product';
protected $crud = null;
protected function setup()
{
$model = new DataModel();
$model->db('products', 'productId');
$this->crud = Doc::create($this, $model, function (BluePrint $input) {
$input->text('productName', 'Product Name')->required();
$input->select('categoryId', 'Category')->options('categories.categoryId.categoryName')->required();
$input->number('price', 'Price')->required();
$input->image('image', 'Image');
$input->editor('description', 'Description');
});
return $this->crud;
}
}
This will give us:
- Products listing page with Bulk Action (Duplicate, Delete), Search, Pagination, Sorting by Columns, Actions (Edit, Delete)
- Product create page with all the fields mentioned above
- Product edit page with all the fields mentioned above
- Products trash page: This page will contain deleted items. You can now delete them from trash permanently.
- FormTool Activities: Will store all the activities like what item was created, updated, duplicated, deleted, restored and destroyed permanently.
If you have understood this much then you are good to go to start with the package and come back to get help from the below documentation (I prefer this way of learning new things 😉). If you prefer to read the documentation first then read it below.
We have many cool features like this. This is just a start. If you like this package please show it by giving it a star in github.
This package is still under active development.
You can boost start the setup with this skeleton package: form-tool-skeleton
Thanks
biswadeep/form-tool 适用场景与选型建议
biswadeep/form-tool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 181 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 biswadeep/form-tool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 biswadeep/form-tool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 181
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-04