gearbox-solutions/eloquent-filemaker
Installation
composer require gearbox-solutions/eloquent-filemaker
Publish the config file:
php artisan vendor:publish --provider="GearboxSolutions\EloquentFileMaker\FileMakerServiceProvider"
Configure .env
Add FileMaker credentials to your .env:
FILEMAKER_API_KEY=your_api_key
FILEMAKER_HOST=https://your-filemaker-server.fm
FILEMAKER_DATABASE=your_database
Define a Model
Extend GearboxSolutions\EloquentFileMaker\EloquentFileMakerModel:
use GearboxSolutions\EloquentFileMaker\EloquentFileMakerModel;
class Client extends EloquentFileMakerModel
{
protected $table = 'clients'; // FileMaker layout name
protected $primaryKey = 'client_id';
}
First Query
$client = Client::find(123);
// or
$clients = Client::where('status', 'active')->get();
create(), update(), delete() as with Eloquent.belongsTo, hasMany, etc., via FileMaker layouts.Model Definition
$table to specify the FileMaker layout name.$fillable for mass assignment:
protected $fillable = ['name', 'email', 'status'];
Querying Data
$activeClients = Client::where('status', 'active')->get();
$client = Client::with('orders')->find(1);
$clients = Client::paginate(10);
Relationships
public function orders()
{
return $this->hasMany(Order::class, 'client_id', 'client_id');
}
belongsTo, hasOne, morphTo, etc., as in Eloquent.Custom API Calls
FileMaker::layout('layout_name')->find() for raw API calls:
$data = FileMaker::layout('custom_layout')->find(1, ['field1', 'field2']);
Events and Observers
class ClientObserver
{
public function saved(Client $client)
{
// Post-save logic
}
}
AppServiceProvider:
Client::observe(ClientObserver::class);
$clients = Cache::remember('active_clients', now()->addHours(1), function () {
return Client::where('status', 'active')->get();
});
try {
$client = Client::find(1);
} catch (\Exception $e) {
Log::error("FileMaker API Error: " . $e->getMessage());
}
FileMakerFake for unit tests:
use GearboxSolutions\EloquentFileMaker\Testing\FileMakerFake;
public function test_client_retrieval()
{
FileMakerFake::fake();
$client = Client::find(1);
$this->assertEquals('Test Client', $client->name);
}
Layout Mismatches
$table in the model matches the FileMaker layout name, not the table name.FileMaker::layout('layout_name')->getLayoutSchema();
Field Name Conflicts
field-name) may cause issues. Use $casts to normalize:
protected $casts = [
'field-name' => 'string',
];
API Rate Limits
use GearboxSolutions\EloquentFileMaker\Exceptions\FileMakerException;
try {
$client = Client::find(1);
} catch (FileMakerException $e) {
if ($e->isRateLimited()) {
sleep(2);
retry();
}
}
Primary Key Issues
protected $primaryKey = 'uuid';
public $incrementing = false;
Relationship Caching
with()) may not work as expected if FileMaker layouts aren’t properly linked. Verify relationships with:
$client = Client::with('orders')->find(1);
dd($client->orders->toArray());
Enable API Logging
Add to config/filemaker.php:
'log' => [
'enabled' => true,
'channel' => 'single',
],
Check logs in storage/logs/laravel.log.
Inspect Raw API Calls
Use FileMaker::layout()->toDebugString() to see the last API request/response.
Validate Layout Schema Dump the layout schema to ensure fields match:
dd(FileMaker::layout('clients')->getLayoutSchema());
Custom API Endpoints
Extend the FileMaker facade to support custom endpoints:
FileMaker::extend('custom', function ($app) {
return new CustomFileMakerApi($app);
});
Query Scopes Add reusable scopes:
public function scopeActive($query)
{
return $query->where('status', 'active');
}
Usage:
$clients = Client::active()->get();
Model Events
Override boot() for custom logic:
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->slug = Str::slug($model->name);
});
}
Custom Casts Handle FileMaker-specific data types (e.g., timestamps, containers):
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
'file_container' => 'array',
];
Batch Operations Use chunking for large datasets:
Client::chunk(100, function ($clients) {
foreach ($clients as $client) {
// Process batch
}
});
How can I help you explore Laravel packages today?