thyyppa / laravel-fluent-fm
一个使用流畅查询构建器风格界面的 Laravel 包,用于 FileMaker Server 的数据 API。
Requires
- php: >=7.2
- thyyppa/fluent-fm: ^1.2.4
Requires (Dev)
- nunomaduro/collision: v3.0.1
- orchestra/testbench: ^3.5 || ^4.0
- phpunit/phpunit: 8.5.4
This package is auto-updated.
Last update: 2024-09-29 05:21:42 UTC
README
FluentFM 是一个 PHP 包,使用流畅查询构建器风格界面连接到 FileMaker Server 的数据 API。
要求
- PHP 7.2+
- FileMaker Server 17
- Laravel 5+
安装
使用 Composer
使用以下命令
composer require thyyppa/laravel-fluent-fm
或者在您的 composer.json
文件中包含
{ "require": { "thyyppa/laravel-fluent-fm": "dev-master" } }
准备 FileMaker
重要!所有表和布局都必须包含一个 id
字段。
如果您想使用软删除,您的表和布局必须包含字段 deleted_at
以下字段也推荐使用
created_at
(按最新排序)updated_at
(按最后更新排序)
您希望访问的所有字段都必须在您在通过 api 执行 FileMaker 操作时提供的布局中可用。
理想情况下,这些将是包含所有字段原始数据的隐藏布局,镜像表,但根据您的布局结构,您可能能够使用现有的面向人类的布局。
确保在您的权限集中启用了 fmrest
,您可以在
文件 > 管理 > 安全 > [高亮用户] > 权限集 [编辑]
同时确保服务器上启用了数据 API。
如果您的服务器安装在本地,此链接应带您到那里
https://:16001/admin-console/app/connectors/fmdapi
否则将 localhost
替换为服务器地址。
注册包
此包具有自动发现功能,因此注册提供者和外观通常不是必需的,但如果自动发现对您不起作用,您可以根据以下示例手动注册包。
在 config/app.php
中注册服务提供者(可选)
'providers' => [ // Other Service Providers Hyyppa\LaravelFluentFM\Providers\LaravelFluentFMServiceProvider::class, ],
在 config/app.php
中注册外观别名(可选)
'aliases' => [ // Other Aliases Hyyppa\LaravelFluentFM\Facades\FluentFM::class, ]
配置
通过运行发布配置文件(可选)
php ./artisan vendor:publish --provider="Hyyppa\\LaravelFluentFM\\Providers\\LaravelFluentFMServiceProvider"
设置环境变量
在您的 .env
文件中,添加以下项
FILEMAKER_FILE=[FileMaker file name without extension] FILEMAKER_HOST=[FileMaker server address] FILEMAKER_USER=[FileMaker file user] FILEMAKER_PASS=[FileMaker file password]
使用
从布局获取记录
<?php use Hyyppa\LaravelFluentFM\Facades\FluentFM; // get a single record as array $record = FluentFM::record('layout', 'id')->get(); // get multiple records as array $records = FluentFM::records('layout')->limit(10)->get();
执行查找操作
$bobs = FluentFM::find('customers')->where('first','Bob')->get();
创建记录
$recordId = FluentFM::create('customers', [ 'id' => 13 'first' => 'Robert', 'last' => 'Paulson', 'phone' => '406-555-0112', ]);
更新记录
// if multiple records are matched each will be updated FluentFM::update('customers', [ 'phone' => '406-555-0199' ]) ->where('id',13) ->limit(1) ->exec();
删除记录
如果您想使用软删除,您的表和布局必须包含字段 deleted_at
// hard delete removes record FluentFM::delete('customers') ->where('id',13) ->limit(1) ->exec(); // soft delete sets record's deleted_at field FluentFM::softDelete('customers') ->where('id',13) ->limit(1) ->exec(); // undeletes soft deleted records FluentFM::undelete('customers') ->where('id',13) ->limit(1) ->exec(); // returns matching records that have not been soft deleted $active = FluentFM::find('customers') ->where('first','Bob') ->withoutDeleted() ->get(); // returns matching records even if soft deleted (default behavior) $all = FluentFM::find('customers') ->where('first','Bob') ->withDeleted() ->get();
将文件上传和下载到记录的容器中
// if query matches multiple, file will be added to each FluentFM::upload('customers', 'photo', './path/to/photo.jpg') ->where('id', 13) ->limit(1) ->exec(); // if query matches multiple, all files will be downloaded to path FluentFM::download('customers', 'photo', './save/to/path/') ->where('id', 13) ->limit(1) ->exec();
运行 FileMaker 脚本
FluentFM::find('customers') ->where('id',13) ->script('scriptname', 'parameter') ->presort('presort_scriptname', 'presort_scriptparam') ->prerequest('prerequest_scriptname', 'prerequest_scriptparam') ->get()
链式命令
... FluentFM::find( <layout> ) FluentFM::update( <layout>, [fields], [recordId] ) FluentFM::delete( <layout>, [recordId] ) FluentFM::softDelete( <layout>, [recordId] ) FluentFM::undelete( <layout>, [recordId] ) FluentFM::upload( <layout>, <field>, <filename>, [recordId] ) FluentFM::download( <layout>, <field>, [output_dir], [recordId] )
链式修饰符
... ->record( <layout>, <id> ) ->records( <layout>, [id] ) ->limit( <limit> ) ->offset( <offset> ) ->sort( <field>, [ascending] ) ->sortAsc( <field> ) ->sortDesc( <field> ) ->withPortals() ->withoutPortals() ->where( <field>, <params> ) // multiple calls act as "and" ->orWhere( <field>, <params> ) ->whereEmpty( <field> ) ->has( <field> ) ->whereNotEmpty( <field> ) ->withDeleted() ->withoutDeleted() ->script( <script>, [param], [type] ) ->prerequest( <script>, [param] ) ->presort( <script>, [param] )
链式方法
... ->get() ->exec() ->create( <layout>, [fields] ) ->latest( <layout>, [field] ) # table must have created_at field if [field] undefined ->oldest( <layout>, [field] ) # table must have created_at field if [field] undefined ->lastUpdate( <layout>, [field] ) # table must have updated_at field if [field] undefined ->first() ->last()
其他命令
... // set global fields on table FluentFM::globals( [table], [ key => value ] ) // clear query parameters FluentFM::clearQuery() // clear query parameters and reset to default options FluentFM::reset()
许可
MIT 许可
免责声明
此项目是一个独立实体,未经 FileMaker, Inc. 授权、赞助或以任何其他方式关联。FileMaker 是 FileMaker, Inc. 的商标,在美国和其他国家注册。