@@ -37,38 +37,38 @@ foreach ($products as $prod) {
37
37
}
38
38
39
39
// Get only the first item
40
- $prod = $api ->query('products')->first();
40
+ $prod = $schema ->query('products')->first();
41
41
```
42
42
43
43
### Filters and deletions
44
44
45
45
``` php
46
46
// Retrieve all records of a resource (returns a laravel collection of \OnPage\Thing)
47
47
// NOTE: system fields must be prefixed with the _ symbol
48
- $api ->query('products')
48
+ $schema ->query('products')
49
49
->where('_id', 42) // = is the default operator
50
50
->where('_created_at', '<', '2024-01-01 00:00:00')
51
51
->where('_updated_at', '>=', '2024-01-01 00:00:00')
52
52
->first();
53
53
54
54
// Other filters
55
- $api ->query('products')
55
+ $schema ->query('products')
56
56
->where('name', 'like', 'shoes') // you can specify a different operator
57
57
->where('category.name', 'Nike') // you can query relations
58
58
->where('dimension', '>', 10) // you get it
59
59
->whereIn('size', [42, 43, 44])
60
60
->all(); // returns a collection with all your records
61
61
62
62
// Join filters with the OR clause: get all products for the adidas or nike brands
63
- $api ->query('products')
63
+ $schema ->query('products')
64
64
->whereOneOf(function(\OnPage\QueryBuilder $q) {
65
65
->where('price', 'Nike')
66
66
->where('brand', 'Adidas')
67
67
})
68
68
->all();
69
69
70
70
// Advanced filtering by relation
71
- $api ->query('products')
71
+ $schema ->query('products')
72
72
73
73
// only retrieve products that have at least one associated category
74
74
->whereHas('category')
@@ -88,17 +88,17 @@ $api->query('products')
88
88
->all();
89
89
90
90
// You can just simply move data to trash the same way:
91
- $api ->query('products')
91
+ $schema ->query('products')
92
92
->where(...)
93
93
->delete();
94
94
95
95
// Or delete elements bypassing the trash:
96
- $api ->query('products')
96
+ $schema ->query('products')
97
97
->where(...)
98
98
->delete(forever: true);
99
99
100
100
// Filter by element status trash, any
101
- $api ->query('products')
101
+ $schema ->query('products')
102
102
->where(...)
103
103
->delete(forever: true);
104
104
```
@@ -109,7 +109,7 @@ Use the val() function to get the first value in a field.
109
109
Use the values() function to get all values in a field as a collection.
110
110
111
111
``` php
112
- $cat = $api ->query('categories')->first();
112
+ $cat = $schema ->query('categories')->first();
113
113
echo $cat->id; // item ID
114
114
echo $cat->created_at; // creation date e.g. 2022-01-01 23:33:00
115
115
echo $cat->updated_at; // date of last update to any of the fields e.g. 2022-01-01 23:33:00
@@ -172,28 +172,28 @@ $product->file('cover_image')->link(['x' => 200, 'ext' => 'png'])
172
172
173
173
``` php
174
174
// Speed things up by only loading some fields
175
- $api ->query('products')->loadFields(['title'])->all();
175
+ $schema ->query('products')->loadFields(['title'])->all();
176
176
177
177
// You can also limit the fields on a related item
178
- $api ->query('products')
178
+ $schema ->query('products')
179
179
->with([ 'colors' ])
180
180
->loadRelationFields('colors', ['name', 'image']) // only load 2 fields for the "color" relation
181
181
->all();
182
182
183
183
184
184
// Get a mapping between two fields or a field and the thing ID
185
- $api ->query('products')->map('code');
185
+ $schema ->query('products')->map('code');
186
186
// [ 'MYSKU100' => 1827, 'MYSKU101' => 1828, ... ]
187
187
188
- $api ->query('products')->map('code', 'title');
188
+ $schema ->query('products')->map('code', 'title');
189
189
// [ 'MYSKU100' => 'Apples', 'MYSKU101' => 'Bananas', ... ]
190
190
```
191
191
192
192
### Get thing relations
193
193
194
194
``` php
195
195
// You need to specify the relations using the "with" method
196
- $cat = $api ->query('categories')
196
+ $cat = $schema ->query('categories')
197
197
->with('subcategories')
198
198
->first();
199
199
$subcategories = $cat->rel('subcategories');
@@ -202,12 +202,12 @@ foreach ($subcategories as $subcategory) {
202
202
}
203
203
204
204
// You can also preload nested subcategories
205
- $cat = $api ->query('categories')
205
+ $cat = $schema ->query('categories')
206
206
->with('subcategories.articles.colors')
207
207
->first();
208
208
209
209
// Or you can pass the relations as an array
210
- $products_with_colors = $api ->query('products')
210
+ $products_with_colors = $schema ->query('products')
211
211
->with([ 'colors', 'categories' ])
212
212
->all();
213
213
foreach ($products_with_colors as $prod) {
@@ -218,7 +218,7 @@ foreach ($products_with_colors as $prod) {
218
218
}
219
219
220
220
// If you need to filter the related items you want to download, you can do this:
221
- $cat = $api ->query('categories')
221
+ $cat = $schema ->query('categories')
222
222
->with('subcategories.articles.colors')
223
223
->filterRelation('subcategories.articles', function(\OnPage\QueryBuilder $q) {
224
224
$q->where('is_online', true);
@@ -241,7 +241,7 @@ This class allows you to edit many records at once.
241
241
You can easily obtain the editor calling:
242
242
243
243
``` php
244
- $writer = $api ->resource('categories')->writer();
244
+ $writer = $schema ->resource('categories')->writer();
245
245
```
246
246
247
247
Now that you have a ** Resource Writer** , you can use it to create things:
@@ -269,7 +269,7 @@ $writer->save();
269
269
## Updating a single item (second method)
270
270
271
271
``` php
272
- $product = $api ->query('products')->where('name', 'Plastic Duck')->first();
272
+ $product = $schema ->query('products')->where('name', 'Plastic Duck')->first();
273
273
274
274
$editor = $product->editor();
275
275
$editor->set('description', 'This yellow plastic duck will be your best friend');
0 commit comments