Skip to content

Commit 5eaa0d2

Browse files
committed
Merge branch 'release/2.0.0'
2 parents b977999 + 148e596 commit 5eaa0d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+24891
-1162
lines changed

.vuepress/2.0.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
module.exports = [
2+
{
3+
title: 'Getting Started',
4+
collapsable: false,
5+
children: prefix('getting-started', [
6+
'',
7+
'upgrade',
8+
'core-concepts',
9+
'directory-structure',
10+
]),
11+
},
12+
{
13+
title: 'Tutorial',
14+
collapsable: true,
15+
children: prefix('tutorial', [
16+
'',
17+
'02-models',
18+
'03-server-and-schemas',
19+
'04-relationships',
20+
'05-creating-resources',
21+
'06-modifying-resources',
22+
'07-deleting-resources',
23+
'08-fetching-resources',
24+
]),
25+
},
26+
{
27+
title: 'Servers',
28+
collapsable: false,
29+
children: prefix('servers', [
30+
'',
31+
'events',
32+
]),
33+
},
34+
{
35+
title: 'Schemas',
36+
collapsable: false,
37+
children: prefix('schemas', [
38+
'',
39+
'identifier',
40+
'attributes',
41+
'relationships',
42+
'eager-loading',
43+
'sorting',
44+
'pagination',
45+
'filters',
46+
'soft-deleting',
47+
]),
48+
},
49+
{
50+
title: 'Routing',
51+
collapsable: false,
52+
children: prefix('routing', [
53+
'',
54+
'controllers',
55+
'writing-actions',
56+
'custom-actions',
57+
]),
58+
},
59+
{
60+
title: 'Requests',
61+
collapsable: false,
62+
children: prefix('requests', [
63+
'',
64+
'authorization',
65+
'compliance',
66+
'resources',
67+
'query-parameters',
68+
]),
69+
},
70+
{
71+
title: 'Responses',
72+
collapsable: false,
73+
children: prefix('responses', [
74+
'',
75+
'errors',
76+
]),
77+
},
78+
{
79+
title: 'API Resources',
80+
collapsable: false,
81+
children: prefix('resources', [
82+
'',
83+
'attributes',
84+
'relationships',
85+
'meta',
86+
'links',
87+
]),
88+
},
89+
{
90+
title: 'Digging Deeper',
91+
collapsable: false,
92+
children: prefix('digging-deeper', [
93+
'artisan',
94+
'countable',
95+
'localisation',
96+
'proxies',
97+
'non-eloquent',
98+
'polymorphic-to-many',
99+
]),
100+
},
101+
{
102+
title: 'Testing',
103+
collapsable: false,
104+
children: prefix('testing', [
105+
'',
106+
'resources',
107+
'relationships',
108+
'requests',
109+
'assertions',
110+
]),
111+
}
112+
];
113+
114+
function prefix(prefix, children) {
115+
return children.map(child => `${prefix}/${child}`)
116+
}

.vuepress/config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,21 @@ module.exports = {
3939
{
4040
text: "Version",
4141
link: "/",
42-
items: [{ text: "1.0", link: "/1.0/" }],
42+
items: [
43+
{
44+
text: "2.0",
45+
link: "/2.0/"
46+
},
47+
{
48+
text: "1.0",
49+
link: "/1.0/"
50+
},
51+
],
4352
}
4453
],
4554
sidebar: {
4655
"/1.0/": require("./1.0"),
56+
"/2.0/": require("./2.0"),
4757
},
4858
},
4959

1.0/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ specification-compliant APIs to your Laravel applications.
66
Full details of the JSON:API specification can be found on their
77
[website](https://jsonapi.org).
88

9-
## Laravel JSON:API Features
9+
## Features
1010

11-
This package provides all the capabilities you need to add JSON:API compliant
12-
APIs to your Laravel application. We have extensive support for the full
13-
specification, including:
11+
Laravel JSON:API provides all the capabilities you need to add JSON:API
12+
compliant APIs to your Laravel application. We have extensive support for the
13+
full specification, including:
1414

1515
- Content negotiation
1616
- Fetching resources
@@ -38,3 +38,10 @@ with features such as:
3838

3939
And finally, we have an extensive range of test helpers: to make
4040
test driven development a breeze.
41+
42+
## Get Started
43+
44+
Get start by heading to the [installation guide.](./getting-started)
45+
46+
Or if you're new to JSON:API or want a great intro the Laravel JSON:API, then
47+
try our [tutorial.](./tutorial)

1.0/getting-started/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Requirements
66

7-
- PHP: `^7.4|^8.0`
7+
- PHP: `^7.4|8.0.*`
88
- Laravel: `^8.30`
99

1010
## Installation
@@ -19,8 +19,8 @@ dependency. This adds test helpers as described in the
1919
Install both packages using [Composer](https://getcomposer.org):
2020

2121
```bash
22-
composer require laravel-json-api/laravel
23-
composer require --dev laravel-json-api/testing
22+
composer require laravel-json-api/laravel:^1.1
23+
composer require --dev laravel-json-api/testing:^1.1
2424
```
2525

2626
The `LaravelJsonApi\Laravel\ServiceProvider` is auto-discovered and registered

1.0/requests/query-parameters.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,47 @@ This is to avoid collisions with the `Illuminate\Validation\Rule` class.
356356

357357
The available rules are:
358358

359+
- [Boolean](#boolean)
359360
- [Field Sets](#field-sets)
360361
- [Filter](#filter)
361362
- [Include Paths](#include-paths)
362363
- [Not Supported](#not-supported)
363364
- [Page](#page)
364365
- [Sort](#sort)
365366

367+
### Boolean
368+
369+
As query parameters are taken from the string URL, their values are always
370+
strings. Our filters classes have an `asBoolean()` helper method that tells the
371+
filter to parse the string value to a boolean - which internally uses PHP's
372+
`filter_var` function.
373+
374+
To validate a query parameter string value as a boolean, use our `boolean` rule
375+
combined with the `asString()` method to tell the rule that you expect the
376+
boolean to be a string. For example:
377+
378+
```php
379+
use LaravelJsonApi\Validation\Rule as JsonApiRule;
380+
381+
public function rules(): array
382+
{
383+
return [
384+
'filter.published' => JsonApiRule::boolean()->asString(),
385+
386+
// ...
387+
];
388+
}
389+
```
390+
391+
This will allow the client to submit `"true"`, `"false"`, `"0"` and `"1"` as
392+
the string boolean values.
393+
394+
:::tip
395+
Laravel does have a `boolean` rule that you could use. However this rule does
396+
not allow `"true"` and `"false"` as values. Therefore we recommend using our
397+
boolean rule for this scenario.
398+
:::
399+
366400
### Field Sets
367401

368402
Our field sets rule validates the `fields` parameter according to
@@ -471,7 +505,7 @@ use LaravelJsonApi\Validation\Rule as JsonApiRule;
471505
public function rules(): array
472506
{
473507
return [
474-
'filter' => [
508+
'include' => [
475509
'nullable',
476510
'string',
477511
JsonApiRule::includePaths(),

1.0/requests/resources.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,23 @@ the different request types described in this chapter, i.e. creating/updating
525525
a resource, modifying a relationship and deleting a resource.
526526
:::
527527

528+
### Validating Booleans
529+
530+
In JSON, a boolean is always `true` or `false`. However Laravel's `boolean`
531+
validation rule is _loosely typed_ - i.e. it will accept `true`, `false`, `0`,
532+
`1`, `"0"`, and `"1"` as valid values.
533+
534+
For JSON it is better to by _strictly typed_ for boolean values. Use our
535+
`boolean` rule to enforce only accepting `true` and `false` as valid values:
536+
537+
```php
538+
use LaravelJsonApi\Validation\Rule as JsonApiRule;
539+
540+
return [
541+
'published' => JsonApiRule::boolean(),
542+
];
543+
```
544+
528545
### Validating Dates
529546

530547
JSON:API
@@ -553,6 +570,34 @@ return [
553570
];
554571
```
555572

573+
### Validating Numbers
574+
575+
Laravel's `integer` and `numeric` rules are _loosely typed_ - that is, they will
576+
accept integers, floats and string representations of numbers. JSON however
577+
can be _strictly typed_ - i.e. when JSON decoded we can expect a value to be
578+
a PHP integer or float.
579+
580+
If you have a field that can accept an integer or float, use our `number`
581+
validation rule to ensure it is strictly typed:
582+
583+
```php
584+
use LaravelJsonApi\Validation\Rule as JsonApiRule;
585+
586+
return [
587+
'published' => JsonApiRule::number(),
588+
];
589+
```
590+
591+
To only accept integers, use the `integer` rule:
592+
593+
```php
594+
use LaravelJsonApi\Validation\Rule as JsonApiRule;
595+
596+
return [
597+
'published' => JsonApiRule::integer(),
598+
];
599+
```
600+
556601
### Required Rule
557602

558603
Using the `required` rule can result in a JSON:API error object with a JSON

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy