appoly / smart-schema
此包的最新版本(0.7.12)没有可用的许可证信息。
Laravel 的表单辅助工具
0.7.12
2019-12-12 11:59 UTC
- dev-master
- 0.7.12
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.13
- 0.4.12
- 0.4.11
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.2
- 0.0.1
- dev-dependabot/add-v2-config-file
- dev-analysis-XWRgRP
This package is auto-updated.
Last update: 2024-09-29 04:36:58 UTC
README
厌倦了重复自己?此包将所有与字段相关的内容集中在一起。
导航
快速使用
添加到 composer.json
"appoly/smart-schema": "^0.6.3",
简介
不需要创建迁移、请求、表单视图和设置可填充字段,我们可以创建一个智能迁移来处理所有这些。
示例迁移
SmartSchema::create('sites', function ($table) {
$table->increments("id");
$table->integer("name");
$table->text("name")
->nullable()
->required()
->fillable()
->max(5)
->forms([
'type' => 'text',
'label' => 'Site name'
]);
$table->timestamps();
});
字段选项
字段类型
标准字段类型可用。
$table->text("name")
$table->integer("user_id")
$table->float("latitude")
等等...
虚拟字段
在某些情况下,我们可能需要在表单中添加不直接对应数据库表的字段。
然后我们可以使用
$table->virtual("slot")->forms(...
验证规则
这些可以在迁移中的字段创建时链接。
示例
$table->text("email")->required()->email();
可用的规则
->unique()
->required()
->email()
->max( val )
->min( val )
可以通过添加自定义验证规则
->addRule( rule )
在控制器中存储对象时,应该使用对象类型调用验证辅助函数
public function store(Request $request) {
SchemaHelper::validate($request, 'sites');
// Process the request
// ...
}
模型属性
fillable()
转换
->array()
->datetime()
模型 必须 有 SmartField
特性才能使用 fillable()
或任何属性转换。
class User extends Model
{
use SmartField;
}
表单
表单辅助工具将根据字段数据生成表单(目前为 Bootstrap 4)。
在迁移中使用 ->forms([...
显示自动生成的表单中的字段
->forms([
'type' => 'text',
'label' => 'Site name'
])
渲染基本表单
{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store')) !!}
需要一组选项的复选框表单字段,如选择框和单选按钮。
对于以下字段
$table->id("role")
->forms([
'type' => 'select', // or 'type' => 'radio'
'label' => 'Role'
]);
选项可以如此传递
{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store'), [
'select_options' => [
'role_id' => ['User', 'Admin']
]
]) !!}
或者使用键
{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store'), [
'select_options' => [
'role_id' => [
10001 => 'User',
20001 => 'Admin'
]
]
]) !!}
代码生成
此包包括一个控制台命令,可以设置模板控制器和视图代码。
php artisan crud:generate {resource_name_singular}
例如
php artisan crud:generate client