You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-59
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ Because this class extends Model, all of the regular eloquent methods may show a
87
87
### Setting a layout
88
88
Your queries against your FileMaker database require you to get data from a particular layout. Eloquent-FileMaker supports Laravel's name guessing for tables, but in case your layout names don't match you can specify a layout name to use with your models by setting the `$layout` property on your model class.
89
89
90
-
```
90
+
```php
91
91
protected $layout = 'MyLayout';
92
92
```
93
93
@@ -99,15 +99,15 @@ This package supports both reading and writing container field data. Container f
99
99
100
100
#### Writing to container fields
101
101
When setting a container field you should set the value to be an `Illuminate/HTTP/File` or `Illuminate/HTTP/UploadedFile` object. These attributes will be written back to your container fields along with any other model updates when the `save()` method is called on your model object.
102
-
```
102
+
```php
103
103
$file = new File(storage_path('app/public/gator.jpg'));
104
104
$newPet->photo = $file;
105
105
$newPet->save();
106
106
```
107
107
108
108
#### Custom filenames when inserting files into containers
109
109
By default, files are inserted into containers using the filename of the file you are inserting. If you wish to set a new filename when the file is inserted into the container you can do so by passing the file and filename together in an array when setting your container.
110
-
```
110
+
```php
111
111
$file = new File(storage_path('app/public/gator.jpg'));
112
112
$newPet->photo = [$file, 'fluffy.jpg'];
113
113
$newPet->save();
@@ -116,15 +116,15 @@ By default, files are inserted into containers using the filename of the file yo
116
116
### Renaming and Mapping FileMaker Fields
117
117
Sometimes you might be working with a FileMaker database with inconvenient field names. These fields can be remapped to model attributes by setting the `$fieldMapping` attribute. This should be an array of strings, mapping FileMaker Field Name => New Attribute Name. You can then use these names as regular Eloquent attributes and they will work with the correct fields in FileMaker
118
118
119
-
```
119
+
```php
120
120
protected $fieldMapping = [
121
121
'My Inconveniently Named Field' => 'a_much_better_name'
122
122
];
123
123
```
124
124
125
125
and then you can get/set the attributes via....
126
126
127
-
```
127
+
```php
128
128
$myModel->a_much_better_name = 'my new value';
129
129
```
130
130
@@ -133,7 +133,7 @@ If you have included fields from related records through relationships on your D
133
133
134
134
For example, if you have a Person table with a one-to-one relationship to a record of the first car they owned:
135
135
136
-
```
136
+
```php
137
137
protected $fieldMapping = [
138
138
'person_CARfirst::color' => 'first_car_color',
139
139
'person_CARfirst::make' => 'first_car_make',
@@ -143,7 +143,7 @@ protected $fieldMapping = [
143
143
144
144
The related data can be get/set just like any other attribute of the model. The data will be read from and written back to the first related record.
145
145
146
-
```
146
+
```php
147
147
$personFirstCarColor = $person->first_car_color;
148
148
```
149
149
@@ -153,22 +153,22 @@ Portal data can be accessed as an attribute based on the portal's object name on
153
153
154
154
For example, if you have a portal on a layout whose object name is "person_pet_portal" based on the "person_PET" relationship you can access your portal data via an array of that attribute:
This package has special handling for casting FileMaker Timestamp and Date fields to Carbon instances for you. To take advantage of this, you must map the fields as you would with a native Laravel Model class. You can use the `$casts` property as you normally would for these attributes.
170
170
171
-
```
171
+
```php
172
172
protected $casts = [
173
173
'nextAppointment' => 'datetime',
174
174
'birthday' => 'date',
@@ -178,14 +178,14 @@ This package has special handling for casting FileMaker Timestamp and Date field
178
178
The format Date and Timestamp fields written to FileMaker can be changed via the `$dateFormat` property of your model. This value must be compatible with the format output from the FileMaker Data API for Timestamp values and will be the format written back into your database. One important requirement is that this must be a full timestamp format, not just a date format.
@@ -236,70 +236,70 @@ where `host` is the IP address or host name of the master machine running FileMa
236
236
Here are a list of methods which will allow you to set the parameters for the Data API features. Note that most of these can be chain-called, like with the standard query builder.
237
237
238
238
#### Start with
239
-
```
240
-
table
241
-
connection
242
-
layout (alias for table)
239
+
```php
240
+
FM::table()
241
+
FM::connection()
242
+
FM::layout() // alias for table()
243
243
```
244
244
245
245
#### Chainable
246
-
```
247
-
(standard query-builder stuff, like where, orderBy, etc)
248
-
limit
249
-
offset
250
-
script
251
-
scriptParam
252
-
scriptPresort
253
-
scriptPresortParam
254
-
scriptPrerequest
255
-
scriptPrerequestParam
256
-
layoutResponse
257
-
portal
258
-
sort (alias for the native orderBy)
259
-
omit
260
-
fieldData
261
-
portalData
246
+
```php
247
+
// standard query-builder stuff like where, orderBy, etc.
248
+
->limit()
249
+
->offset()
250
+
->script()
251
+
->scriptParam()
252
+
->scriptPresort()
253
+
->scriptPresortParam()
254
+
->scriptPrerequest()
255
+
->scriptPrerequestParam()
256
+
->layoutResponse()
257
+
->portal()
258
+
->sort() // alias for the native orderBy()
259
+
->omit()
260
+
->fieldData()
261
+
->portalData()
262
262
```
263
263
264
264
#### Final-chain-link methods
265
-
```
266
-
(standard query-builder stuff, like get, first, etc.)
267
-
findByRecordId
268
-
performScript
269
-
setContainer
270
-
duplicate
271
-
createRecord
272
-
getLayoutMetadata
265
+
```php
266
+
// standard query-builder stuff like get, first, etc.
It is possible to have relationships between native Laravel Model objects from your MySQL database and FMModels created from your FileMaker database. To do this, you will need to set up both connections in your `database.config` file and then make sure your models are pointing to the right connection by setting the `$connection` propety in your Model and FMModel classes.
341
-
```
341
+
```php
342
342
protected $connection = 'theConnectionName';
343
343
```
344
344
345
345
Once they're set correctly, you can create relationships, such as a belongsTo, by manually creating a new eloquent-filemaker belongsTo object and setting the appropriate keys.
346
346
347
347
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
348
348
349
-
User.php
350
-
351
-
```
349
+
```php
350
+
class User extends Model
351
+
{
352
352
public function company()
353
353
{
354
354
return new \GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
355
355
}
356
-
356
+
}
357
357
```
358
358
359
359
With this relationship created we can now get an FMModel of the Company the User belongs to like a normal relationship in a single database.
360
360
361
-
```
362
-
// set $company to a FMModel of the User's Company
361
+
```php
362
+
// set $company to a FMModel of the User's Company
0 commit comments