PHP code example of gearbox-solutions / eloquent-filemaker
1. Go to this page and download the library: Download gearbox-solutions/eloquent-filemaker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gearbox-solutions / eloquent-filemaker example snippets
'filemaker' => [
'driver' => 'filemaker',
'host' => env('DB_HOST', 'fms.mycompany.com'),
'database' => env('DB_DATABASE', 'MyFileName'),
'username' => env('DB_USERNAME', 'myusername'),
'password' => env('DB_PASSWORD', ''),
'prefix' => env('DB_PREFIX', ''),
'version' => env('DB_VERSION', 'vLatest'),
'protocol' => env('DB_PROTOCOL', 'https'),
'cache_session_token' => env('DB_CACHE_SESSION_TOKEN', true), // set to false to log out after each reqeust. This can be slower than re-using a session token, but allows for globals to be set for individual user values.
'empty_strings_to_null' => env('DB_EMPTY_STRINGS_TO_NULL', true), // set to false to return empty strings instead of null values when fields are empty in FileMaker
]
protected $layout = 'MyLayout';
$file = new File(storage_path('app/public/gator.jpg'));
$newPet->photo = $file;
$newPet->save();
$file = new File(storage_path('app/public/gator.jpg'));
$newPet->photo = [$file, 'fluffy.jpg'];
$newPet->save();
// set the ModId and flag it submit the modification ID when saving the record
$person->withModId(12)->save();
protected $withModId = true;
// Person.php
class Person extends FMModel
{
protected $layout = "person";
protected $fieldMapping = [
'first name' => 'nameFirst',
'last name' => 'nameLast'
];
protected $casts = [
'birthday' => 'date',
];
public function pets(){
return $this->hasMany(Pet::class);
}
}
FM::table()
FM::connection()
FM::layout() // alias for table()
FM::setGlobalFields() // not chainable
// standard query-builder stuff like where, orderBy, etc.
->limit( $value )
->offset( $value )
->script( $scriptName, $param)
->scriptParam( $param )
->scriptPresort( $scriptName, $param
->scriptPresortParam( $param )
->scriptPrerequest( $scriptName, $param )
->scriptPrerequestParam( $param )
->layoutResponse( $layoutName )
->portal( $portalName )
->portalLimit( $portalName, $limit )
->portalOffset( $portalName, $startingRecord )
->sort() // alias for the native orderBy()
->omit() // change the request to an "omit" request
->modId( string $modId ) // set the modId to submit when editing a record
->fieldData( $array )
->portalData( $array )
// standard query-builder stuff like get, first, etc.
->findByRecordId()
->performScript()
->setContainer()
->duplicate()
->createRecord()
->getLayoutMetadata()
// User.php
use GearboxSolutions\EloquentFileMaker\Database\Eloquent\Concerns\HasHybridRelationships;
class User extends Model
{
use HasHybridRelationships;
public function company()
{
// The Company class is an FMModel and is stored in FileMaker
// The correct relationship will be resolved automatically thanks to the HasHybridRelationships trait
return $this->belongsTo(Company::class, 'company_id', 'id');
}
}
// set $company to a FMModel of the User's Company
$company = $user->company;
// User.php
class User extends Model
{
public function company()
{
// The Company class is an FMModel and is stored in FileMaker
return new \GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
}
}