FluentFM is a PHP package that connects to FileMaker Server's Data API using a fluent query builder style interface.
- PHP 7.1+
- FileMaker Server 17
Use the command
composer require thyyppa/fluent-fm
or include in your composer.json
file
{
"require": {
"thyyppa/fluent-fm": "dev-master"
}
}
All records must contain the following fields:
- id
- created_at
- updated_at
- deleted_at
All fields that you wish to access must be available in the layout that you provide while performing FileMaker operations through the api.
Ideally these will be hidden layouts that contain all fields raw, mirroring the table, but depending on your layout structure you may be able to use existing human-facing layouts.
Ensure that fmrest
is enabled on your privilege set, which you can define in
File > Manage > Security > [highlight user] > Privilege Set [Edit]
Also be sure that the Data API is enabled on the server.
If your server is installed locally this link should take you there:
http://localhost:16001/admin-console/app/connectors/fmdapi
Otherwise replace localhost
with the server address.
<?php
use Hyyppa\FluentFM\Connection\FluentFMRepository;
$fm = new FluentFMRepository([
'file' => 'FilemakerFilename',
'host' => '127.0.0.1',
'user' => 'Admin',
'pass' => 'secret',
]);
// get a single record as array
$record = $fm->record('layout', 'id')->get();
// get multiple records as array
$records = $fm->records('layout')->limit(10)->get();
$bobs = $fm->find('customers')->where('first','Bob')->get();
$recordId = $fm->create('customers', [
'id' => 13
'first' => 'Robert',
'last' => 'Paulson',
'phone' => '406-555-0112',
]);
// if multiple records are matched each will be updated
$fm->update('customers', [ 'phone' => '406-555-0199' ])
->where('id',13)
->limit(1)
->exec();
// hard delete removes record
$fm->delete('customers')
->where('id',13)
->limit(1)
->exec();
// soft delete sets record's deleted_at field
$fm->softDelete('customers')
->where('id',13)
->limit(1)
->exec();
// undeletes soft deleted records
$fm->undelete('customers')
->where('id',13)
->limit(1)
->exec();
// if query matches multiple, file will be added to each
$fm->upload('customers', 'photo', './path/to/photo.jpg')
->where('id', 13)
->limit(1)
->exec();
// if query matches multiple, all files will be downloaded to path
$fm->download('customers', 'photo', './save/to/path/')
->where('id', 13)
->limit(1)
->exec();
$fm->find('customers')
->where('id',13)
->script('scriptname', 'parameter')
->presort('presort_scriptname', 'presort_scriptparam')
->prerequest('prerequest_scriptname', 'prerequest_scriptparam')
->get()
...
->find( <layout> )
->update( <layout>, [fields], [recordId] )
->delete( <layout>, [recordId] )
->softDelete( <layout>, [recordId] )
->undelete( <layout>, [recordId] )
->upload( <layout>, <field>, <filename>, [recordId] )
->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> )
->whereEmpty( <field> )
->has( <field> )
->whereNotEmpty( <field> )
->withDeleted()
->script( <script>, [param], [type] )
->prerequest( <script>, [param] )
->presort( <script>, [param] )
...
->get()
->exec()
->create( <layout>, [fields] )
->latest( <layout>, [field] )
->lastUpdate( <layout> )
->oldest( <layout>, [field] )
->first()
->last()
...
// set global fields on table
->global( [table], [ key => value ] )
MIT License
This project is an independent entity and has not been authorized, sponsored, or otherwise affiliated with FileMaker, Inc. FileMaker is a trademark of FileMaker, Inc., registered in the U.S. and other countries.