Skip to content

Commit b9b3d59

Browse files
committed
#ref correct README.md
1 parent 50fc049 commit b9b3d59

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,38 @@ foreach ($products as $prod) {
3737
}
3838

3939
// Get only the first item
40-
$prod = $api->query('products')->first();
40+
$prod = $schema->query('products')->first();
4141
```
4242

4343
### Filters and deletions
4444

4545
```php
4646
// Retrieve all records of a resource (returns a laravel collection of \OnPage\Thing)
4747
// NOTE: system fields must be prefixed with the _ symbol
48-
$api->query('products')
48+
$schema->query('products')
4949
->where('_id', 42) // = is the default operator
5050
->where('_created_at', '<', '2024-01-01 00:00:00')
5151
->where('_updated_at', '>=', '2024-01-01 00:00:00')
5252
->first();
5353

5454
// Other filters
55-
$api->query('products')
55+
$schema->query('products')
5656
->where('name', 'like', 'shoes') // you can specify a different operator
5757
->where('category.name', 'Nike') // you can query relations
5858
->where('dimension', '>', 10) // you get it
5959
->whereIn('size', [42, 43, 44])
6060
->all(); // returns a collection with all your records
6161

6262
// Join filters with the OR clause: get all products for the adidas or nike brands
63-
$api->query('products')
63+
$schema->query('products')
6464
->whereOneOf(function(\OnPage\QueryBuilder $q) {
6565
->where('price', 'Nike')
6666
->where('brand', 'Adidas')
6767
})
6868
->all();
6969

7070
// Advanced filtering by relation
71-
$api->query('products')
71+
$schema->query('products')
7272

7373
// only retrieve products that have at least one associated category
7474
->whereHas('category')
@@ -88,17 +88,17 @@ $api->query('products')
8888
->all();
8989

9090
// You can just simply move data to trash the same way:
91-
$api->query('products')
91+
$schema->query('products')
9292
->where(...)
9393
->delete();
9494

9595
// Or delete elements bypassing the trash:
96-
$api->query('products')
96+
$schema->query('products')
9797
->where(...)
9898
->delete(forever: true);
9999

100100
// Filter by element status trash, any
101-
$api->query('products')
101+
$schema->query('products')
102102
->where(...)
103103
->delete(forever: true);
104104
```
@@ -109,7 +109,7 @@ Use the val() function to get the first value in a field.
109109
Use the values() function to get all values in a field as a collection.
110110

111111
```php
112-
$cat = $api->query('categories')->first();
112+
$cat = $schema->query('categories')->first();
113113
echo $cat->id; // item ID
114114
echo $cat->created_at; // creation date e.g. 2022-01-01 23:33:00
115115
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'])
172172

173173
```php
174174
// Speed things up by only loading some fields
175-
$api->query('products')->loadFields(['title'])->all();
175+
$schema->query('products')->loadFields(['title'])->all();
176176

177177
// You can also limit the fields on a related item
178-
$api->query('products')
178+
$schema->query('products')
179179
->with([ 'colors' ])
180180
->loadRelationFields('colors', ['name', 'image']) // only load 2 fields for the "color" relation
181181
->all();
182182

183183

184184
// 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');
186186
// [ 'MYSKU100' => 1827, 'MYSKU101' => 1828, ... ]
187187

188-
$api->query('products')->map('code', 'title');
188+
$schema->query('products')->map('code', 'title');
189189
// [ 'MYSKU100' => 'Apples', 'MYSKU101' => 'Bananas', ... ]
190190
```
191191

192192
### Get thing relations
193193

194194
```php
195195
// You need to specify the relations using the "with" method
196-
$cat = $api->query('categories')
196+
$cat = $schema->query('categories')
197197
->with('subcategories')
198198
->first();
199199
$subcategories = $cat->rel('subcategories');
@@ -202,12 +202,12 @@ foreach ($subcategories as $subcategory) {
202202
}
203203

204204
// You can also preload nested subcategories
205-
$cat = $api->query('categories')
205+
$cat = $schema->query('categories')
206206
->with('subcategories.articles.colors')
207207
->first();
208208

209209
// Or you can pass the relations as an array
210-
$products_with_colors = $api->query('products')
210+
$products_with_colors = $schema->query('products')
211211
->with([ 'colors', 'categories' ])
212212
->all();
213213
foreach ($products_with_colors as $prod) {
@@ -218,7 +218,7 @@ foreach ($products_with_colors as $prod) {
218218
}
219219

220220
// 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')
222222
->with('subcategories.articles.colors')
223223
->filterRelation('subcategories.articles', function(\OnPage\QueryBuilder $q) {
224224
$q->where('is_online', true);
@@ -241,7 +241,7 @@ This class allows you to edit many records at once.
241241
You can easily obtain the editor calling:
242242

243243
```php
244-
$writer = $api->resource('categories')->writer();
244+
$writer = $schema->resource('categories')->writer();
245245
```
246246

247247
Now that you have a **Resource Writer**, you can use it to create things:
@@ -269,7 +269,7 @@ $writer->save();
269269
## Updating a single item (second method)
270270

271271
```php
272-
$product = $api->query('products')->where('name', 'Plastic Duck')->first();
272+
$product = $schema->query('products')->where('name', 'Plastic Duck')->first();
273273

274274
$editor = $product->editor();
275275
$editor->set('description', 'This yellow plastic duck will be your best friend');

0 commit comments

Comments
 (0)