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
+62-10Lines changed: 62 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Sessions will be maintained on a per-connection basis and tokens will automatica
55
55
#### Prefix
56
56
The prefix configuration option adds a prefix to each of the layout/table names which you specify. You don't need to specify a prefix, but it can be very convenient to do so.
57
57
58
-
It is good practice to create layouts specifically for the Data API to use, rather than using your regular GUI or developer layouts, which may be slow and have unnecessary fields on them. Creating layouts specifically for your web applications allows for you to optimize your Data API usage and maximize the performance of your web application. With this in mind, an easy way to manage these layout is to organize them together in a folder and give them all a prefix so that you can know what they are used for.
58
+
It is good practice to create layouts specifically for the Data API to use, rather than using your regular GUI or developer layouts, which may be slow and have unnecessary fields on them. Creating layouts specifically for your web applications allows for you to optimize your Data API usage and maximize the performance of your web application. With this in mind, an easy way to manage these layout is to organize them together in a folder and give them all a prefix so that you can know what they are used for.
59
59
60
60
As an example, let's say you have three tables - Organizations, Contacts, and Invoices. You may way to create layouts for your web application, such as "dapi-organizations", "dapi-contacts" and "dapi-invoices". If you prefix them all with the same text you can set the prefix value so that you can refer to them as just "organizations", "contacts" and "invoices" in Laravel. If you name your model classes correctly following Laravel's naming guidelines you'll even be able to have the layouts automatically resolve for you and you won't have to enter them manually!
61
61
@@ -65,7 +65,7 @@ Creating model classes is the easiest way to access your FileMaker data, and is
65
65
66
66
#### Things that work
67
67
68
-
The FMModel class extends the base Laravel Model class, and can be used very similarly. It supports many standard Eloquent query builder features for working with data, such as where(), find(), id(), orderBy(), delete(), save(), and many more!
68
+
The FMModel class extends the base Laravel Model class, and can be used very similarly. It supports many standard Eloquent query builder features for working with data, such as where(), find(), id(), orderBy(), delete(), save(), and many more!
69
69
70
70
Model features like accessors and mutators are supported, as well as automatic table/layout name resolution, event triggers, observers, belongsTo, hasOne, and hasMany relationships, serialization (with protected attributes, etc), and as many other things as we can make sure are compatible.
71
71
@@ -91,8 +91,57 @@ This package supports both reading and writing container field data. Container f
91
91
92
92
When setting a container field you should set it as an `Illuminate/HTTP/File` 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.
93
93
94
-
### Mapping FileMaker Fields
95
-
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.
94
+
### Renaming and Mapping FileMaker Fields
95
+
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
96
+
97
+
```
98
+
protected $fieldMapping = [
99
+
'My Inconveniently Named Field' => 'a_much_better_name'
100
+
];
101
+
```
102
+
103
+
and then you can get/set the attributes via....
104
+
105
+
```
106
+
$myModel->a_much_better_name = 'my new value';
107
+
```
108
+
109
+
### Fields from related records
110
+
If you have included fields from related records through relationships on your Data API layouts you will need to add a `$fieldMapping` property to be able to access your related data.
111
+
112
+
For example, if you have a Person table with a one-to-one relationship to a record of the first car they owned:
113
+
114
+
```
115
+
protected $fieldMapping = [
116
+
'person_CARfirst::color' => 'first_car_color',
117
+
'person_CARfirst::make' => 'first_car_make',
118
+
'person_CARfirst::model' => 'first_car_model'
119
+
];
120
+
```
121
+
122
+
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.
123
+
124
+
```
125
+
$personFirstCarColor = $person->first_car_color;
126
+
```
127
+
128
+
129
+
### Portal Data
130
+
Portal data can be accessed as an attribute based on the portal's object name on your FileMaker Layout. Fields can be accessed using array keys of the field name.
131
+
132
+
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.
@@ -104,7 +153,7 @@ This package has special handling for casting FileMaker Timestamp and Date field
104
153
];
105
154
```
106
155
107
-
The format Date and Timestamp fields should be set in 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 difference is that this must be a full timestamp format, not just a date format.
156
+
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.
108
157
109
158
Here are some example formats:
110
159
```
@@ -113,18 +162,21 @@ Here are some example formats:
113
162
```
114
163
115
164
116
-
####Example FMModel Class
165
+
## Example FMModel Class
117
166
```
118
167
class Person extends FMModel
119
168
{
120
169
121
170
protected $layout = "person";
122
171
123
-
// FileMaker Field Name => Model Attributes
124
172
protected $fieldMapping = [
125
173
'first name' => 'nameFirst',
126
174
'last name' => 'nameLast'
127
175
];
176
+
177
+
protected $casts = [
178
+
'birthday' => 'date',
179
+
];
128
180
129
181
130
182
public function pets(){
@@ -149,9 +201,9 @@ Like the FMModel class and Eloquent builder, the goal is to support the same set
149
201
150
202
In addition to the basic query builder features, the `FMBaseQueryBuilder` class, accessed through the `FM` facade or the FMModel eloquent builder has many new FileMaker-specific methods which are available.
151
203
152
-
The FileMaker data API supports a number of parameters on requests for doing things like running scripts and passing parameters at different times in the query process. Check the [FileMaker Data API Guide](https://help.claris.com/en/data-api-guide) and more specifically, the Data API Reference Documentation to see which options each specific call supports.
204
+
The FileMaker data API supports a number of parameters on requests for doing things like running scripts and passing parameters at different times in the query process. Check the [FileMaker Data API Guide](https://help.claris.com/en/data-api-guide) and more specifically, the Data API Reference Documentation to see which options each specific call supports.
153
205
154
-
The Data API Reference Documentation can be viewed on a running FileMaker server by following the instructions in the [API Guide](https://help.claris.com/en/data-api-guide/#reference-information)
206
+
The Data API Reference Documentation can be viewed on a running FileMaker server by following the instructions in the [API Guide](https://help.claris.com/en/data-api-guide/#reference-information)
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.
246
298
247
-
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
299
+
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
0 commit comments