thiktak/filament-sql-nested-builder-form
最新稳定版本:v0.1.0-alpha
Composer 安装命令:
composer require thiktak/filament-sql-nested-builder-form
包简介
Plugin for FilamentPHP - SQL Nested Builder Form Component
关键字:
README 文档
README
An application of thiktak/filament-nested-builder-form for SQL with (not) AND/OR and sub-groups.
Warning
Be careful, this package is not yet recommended for production. Help us with testing and feedback :)
Installation
You can install the package via composer:
composer require thiktak/filament-sql-nested-builder-form
This package is based on thiktak/filament-nested-builder-form.
Usage
// use App\Models\User; use Thiktak\FilamentNestedBuilderForm\Forms\Components\NestedBuilder; use Thiktak\FilamentNestedBuilderForm\Forms\Components\NestedSubBuilder; use Thiktak\FilamentSQLNestedBuilderForm\Forms\Components\SQLNestedBuilder; public static function form(Form $form): Form { return $form ->schema([ Section::make('Nested Builder Form') ->description('Example of the SQL Nested Builder Form (SQL Query)') ->schema([ // configuration is an Array SQLNestedBuilder::make('configuration') // nestedConfiguration apply this set up to all children ->nestedConfiguration(function (NestedSubBuilder $builder, NestedBuilder $parent) { // import default configuration of this package $parent->defaultNestedConfiguration($builder); }) // Display the first Hint as a Raw SQL query of User Model ->hint(function (?array $state) { return SQLNestedBuilder::getFullyLinearizedArrayToEloquent($state, User::query()) ->getQuery() ->toRawSql() ; }) ]), ]); }
Configuration
Change the field Input (name of the field)
Use the nestedConfiguration and set up fieldComponent
SQLNestedBuilder::make('configuration') ->nestedConfiguration(function (NestedSubBuilder $builder, NestedBuilder $parent) { // import default configuration of this package $parent->defaultNestedConfiguration($builder); // Change the TextInput -> Select $parent->fieldComponent( fn () => Select::make('field') ->options([ 'id' => 'User Id', 'email' => 'User email', ]) ->searchable() ); })
Export to SQL (string)
This method will return the Raw SQL of a User model query. $state is the data array.
SQLNestedBuilder::getFullyLinearizedArrayToEloquent($state, User::query()) ->getQuery() ->toRawSql()
Output (example):
select * from `users` where ( ( not ( (`a` = '1') and (`b` in ('2', '3')) and (`a` between '1' and '99') ) or (`email` LIKE '%admin.com%') or (`email` LIKE 'a%') or (`email` LIKE '%com') ) and (`tenant_id` = '1') )
Export to Eloquent
SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state); // If consume the whole array SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state, 'group'); // if level of group SQLNestedBuilder::getFullyLinearizedArrayToSQL(?array $state, 'rule'); // if level of rule
Output (example):
(`a` = '1' AND `b` IN ('2', '3') AND `a` BETWEEN '1' AND '99') AND `email` LIKE '%admin.com%' AND `email` LIKE 'a%' AND `email` LIKE '%com'
Add custom operators
(current solution) Extend the SQLNesterBuilder, and redefine the method loadDefinition() with a call to $this->registerOperator(MyOperator::class)
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-14