deiucanta / smart
Laravel Smart
dev-master
2018-12-21 12:09 UTC
Requires
- doctrine/dbal: ^2.8
- illuminate/console: ^5.6
- illuminate/support: ^5.6
- illuminate/validation: ^5.6
Requires (Dev)
- orchestra/testbench: ^3.8@dev
- phpunit/phpunit: ^7.4@dev
This package is not auto-updated.
Last update: 2024-09-29 05:27:56 UTC
README
不要在生产环境中使用此包!
- 这是一个概念验证。(更新:此包已在拥有25个模型的app中成功使用)
- 代码没有单元测试。(更新:感谢@robsontenorio,我们现在有了基本的单元测试)
- API 不稳定。
我发布这个alpha版本是为了获取对API的反馈,并确保我没有遗漏重要的用例。
此外,我无法独自完成这个项目!我非常愿意接受社区的帮忙。不要害羞!
- 加入讨论(即使不是你的问题)
- 改进文档(如果你发现某些内容难以理解,请提出问题,发送pull请求等)
- 通过代码贡献(我会尽可能引导你)
想法
如果你在模型中定义了字段,你可以得到
- 自动迁移
- 在
save()
上自动验证 - 分组字段定义(名称、模式类型、转换、可填充/受保护、验证规则、模式修饰符、模式索引)
<?php namespace App; use Deiucanta\Smart\Field; use Deiucanta\Smart\Model; class Product extends Model { public function fields() { return [ Field::make('id')->increments(), Field::make('sku')->string()->fillable()->required()->unique()->label("Sku Number"), Field::make('name')->string()->fillable()->required(), Field::make('price')->decimal(6, 2)->fillable()->required()->min(0), Field::make('description')->text()->fillable()->nullable(), Field::make('created_at')->timestamp()->nullable()->index(), Field::make('updated_at')->timestamp()->nullable()->index(), ]; } }
安装
要安装此包,只需运行
composer require deiucanta/smart
用法
创建一个 Smart 模型
php artisan smart:model Product
将模型包含在配置文件中(config/smart.php
)
注意:现在当你创建模型时,这将是自动完成的。
<?php return [ 'models' => [ \App\Product::class, ] ];
创建一个 Smart 迁移
php artisan smart:migration
你应该能在你的迁移目录中看到一个新迁移。要应用迁移,你只需像往常一样运行 php artisan migrate
。
你将在你的应用数据库目录下的 database
目录中找到一个名为 smart.json
的新文件。这就是包存储数据库/模型当前状态的地方。如果你删除该文件并运行 php artisan smart:migration
,它将创建一个新迁移,就像模式为空一样。
API
这些都是你应该能够创建任何类型字段的基元。然而,还有一些更智能的方法你可以使用。
基础方法
类型方法
这些是目前支持的所有Laravel类型。
以下是一些自定义类型,仅作为可以完成的事情的示例。