Skip to content

Commit 16af11a

Browse files
Merge branch 'docs-highlighting' into dev
2 parents fe457c7 + b4954b9 commit 16af11a

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

README.md

+59-59
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Because this class extends Model, all of the regular eloquent methods may show a
8787
### Setting a layout
8888
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.
8989

90-
```
90+
```php
9191
protected $layout = 'MyLayout';
9292
```
9393

@@ -99,15 +99,15 @@ This package supports both reading and writing container field data. Container f
9999

100100
#### Writing to container fields
101101
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
103103
$file = new File(storage_path('app/public/gator.jpg'));
104104
$newPet->photo = $file;
105105
$newPet->save();
106106
```
107107

108108
#### Custom filenames when inserting files into containers
109109
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
111111
$file = new File(storage_path('app/public/gator.jpg'));
112112
$newPet->photo = [$file, 'fluffy.jpg'];
113113
$newPet->save();
@@ -116,15 +116,15 @@ By default, files are inserted into containers using the filename of the file yo
116116
### Renaming and Mapping FileMaker Fields
117117
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
118118

119-
```
119+
```php
120120
protected $fieldMapping = [
121121
'My Inconveniently Named Field' => 'a_much_better_name'
122122
];
123123
```
124124

125125
and then you can get/set the attributes via....
126126

127-
```
127+
```php
128128
$myModel->a_much_better_name = 'my new value';
129129
```
130130

@@ -133,7 +133,7 @@ If you have included fields from related records through relationships on your D
133133

134134
For example, if you have a Person table with a one-to-one relationship to a record of the first car they owned:
135135

136-
```
136+
```php
137137
protected $fieldMapping = [
138138
'person_CARfirst::color' => 'first_car_color',
139139
'person_CARfirst::make' => 'first_car_make',
@@ -143,7 +143,7 @@ protected $fieldMapping = [
143143

144144
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.
145145

146-
```
146+
```php
147147
$personFirstCarColor = $person->first_car_color;
148148
```
149149

@@ -153,22 +153,22 @@ Portal data can be accessed as an attribute based on the portal's object name on
153153

154154
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:
155155

156-
```
156+
```php
157157
// Get the name of the first related Pet
158158
$firstPetName = $person->person_pet_portal[0]['person_PET::name'];
159159
```
160160

161161
You can write back data to the portal the same way:
162-
```
162+
```php
163163
// Set the 'type' of the second related pet in the portal
164-
// $person->person_pet_portal[1]['person_PET::type'] = 'cat';
164+
$person->person_pet_portal[1]['person_PET::type'] = 'cat';
165165
```
166166

167167

168168
### Casting FileMaker Timestamp and Date fields
169169
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.
170170

171-
```
171+
```php
172172
protected $casts = [
173173
'nextAppointment' => 'datetime',
174174
'birthday' => 'date',
@@ -178,14 +178,14 @@ This package has special handling for casting FileMaker Timestamp and Date field
178178
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.
179179

180180
Here are some example formats:
181-
```
181+
```php
182182
protected $dateFormat = 'n/j/Y g:i:s A'; // 7/1/1920 4:01:01 PM
183183
protected $dateFormat = 'n/j/Y G:i:s'; // 7/1/1920 16:01:01
184184
```
185185

186186

187187
## Example FMModel Class
188-
```
188+
```php
189189
class Person extends FMModel
190190
{
191191

@@ -195,7 +195,7 @@ class Person extends FMModel
195195
'first name' => 'nameFirst',
196196
'last name' => 'nameLast'
197197
];
198-
198+
199199
protected $casts = [
200200
'birthday' => 'date',
201201
];
@@ -236,70 +236,70 @@ where `host` is the IP address or host name of the master machine running FileMa
236236
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.
237237

238238
#### 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()
243243
```
244244

245245
#### 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()
262262
```
263263

264264
#### 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.
267+
->findByRecordId()
268+
->performScript()
269+
->setContainer()
270+
->duplicate()
271+
->createRecord()
272+
->getLayoutMetadata()
273273
```
274274

275275
#### Examples:
276276
Perform a find for a person named Jaina
277-
```
277+
```php
278278
$person = FM::table('person')->where('nameFirst', 'Jaina')->first();
279279
```
280280

281281
Find the 10 most recent invoices for a customer
282-
```
282+
```php
283283
$invoices = FM::layout('invoice')->where('customer_id', $customer->id)->orderByDesc('date')->limit(10)->get();
284284
```
285285

286286
Get layout metadata, which includes field, portal, and value list information
287-
```
287+
```php
288288
$layoutMetadata = FM::getLayoutMetadata('MyLayoutName');
289289
```
290290

291291
Get layout metadata for a specific record
292-
```
292+
```php
293293
$layoutMetadata = FM::layout('MyLayoutName')->recordId(879)->getLayoutMetadata();
294294
```
295295

296296
Run a script
297-
```
297+
```php
298298
$result = FM::layout('MyLayoutName')->performScript('MyScriptName');
299299
```
300300

301301
Run a script with JSON data as a parameter
302-
```
302+
```php
303303
$json = json_encode ([
304304
'name' => 'Joe Smith',
305305
'birthday' => '1/1/1970'
@@ -310,12 +310,12 @@ $result = FM::layout('globals')->performScript('New Contact Request'; $json);
310310
```
311311

312312
Perform a script on a database other than the default database connection
313-
```
313+
```php
314314
$result = FM::connection('MyOtherDatabaseConnectionName')->layout('MyLayoutName')->performScript('MyScriptName');
315315
```
316316

317317
Create a record with an array of field data and then perform a script after record creation, within the same request
318-
```
318+
```php
319319
FM::layout('MyLayoutName')->script('ScriptName')->fieldData($data)->createRecord();
320320

321321
```
@@ -326,40 +326,40 @@ Eloquent-FileMaker attempts to automatically re-use session tokens by caching th
326326

327327
If you would like to manually log out and end your session you can do so either through the FM facade or through a model.
328328

329-
```
329+
```php
330330
FM::connection()->disconnect();
331331
```
332332
or
333-
```
333+
```php
334334
MyModel::getConnectionResolver()->connection()->disconnect();
335335
```
336336

337337

338338

339339
## Relating Native Laravel models to FMModels
340340
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
342342
protected $connection = 'theConnectionName';
343343
```
344344

345345
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.
346346

347347
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
348348

349-
User.php
350-
351-
```
349+
```php
350+
class User extends Model
351+
{
352352
public function company()
353353
{
354354
return new \GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
355355
}
356-
356+
}
357357
```
358358

359359
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.
360360

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
363363
$company = $user->company;
364364
```
365365

0 commit comments

Comments
 (0)