Skip to content

Commit 78d1940

Browse files
committed
Merge branch 'develop' of github.com:cloudcreativity/laravel-json-api into develop
2 parents 31e5fdb + 4385665 commit 78d1940

File tree

387 files changed

+2597
-1066
lines changed

Some content is hidden

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

387 files changed

+2597
-1066
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/docs export-ignore
2+
/tests export-ignore
3+
.editorconfig export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
.travis.yml export-ignore
7+
mkdocs.yml export-ignore
8+
phpunit.xml export-ignore

CHANGELOG.md

Lines changed: 366 additions & 273 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
[![Build Status](https://travis-ci.org/cloudcreativity/laravel-json-api.svg?branch=master)](https://travis-ci.org/cloudcreativity/laravel-json-api)
1+
![Tests](https://github.com/cloudcreativity/laravel-json-api/workflows/Tests/badge.svg)
22

33
# cloudcreativity/laravel-json-api
44

5+
## Status
6+
7+
**DO NOT USE THIS PACKAGE FOR NEW PROJECTS - USE [laravel-json-api/laravel](https://github.com/laravel-json-api/laravel)
8+
INSTEAD.**
9+
10+
This package has now been rewritten, substantially improved and released as the `laravel-json-api/laravel` package.
11+
Documentation for the new version is available on our new website [laraveljsonapi.io](https://laraveljsonapi.io) and the
12+
code is now developed under the
13+
[Laravel JSON:API Github organisation.](https://github.com/laravel-json-api)
14+
15+
The `cloudcreativity/laravel-json-api` package is now considered to be the *legacy* package. As we know it is in use in
16+
a lot of production applications, it will continue to receive bug fixes and updates for new Laravel versions. However,
17+
it is no longer supported for new features.
18+
19+
If you are starting a new project, you MUST use the
20+
[new package `laravel-json-api/laravel`.](https://github.com/laravel-json-api/laravel)
21+
22+
## Introduction
23+
524
Build feature-rich and standards-compliant APIs in Laravel.
625

726
This package provides all the capabilities you need to add [JSON API](http://jsonapi.org)
@@ -38,25 +57,23 @@ The following additional features are also supported:
3857
From [jsonapi.org](http://jsonapi.org)
3958

4059
> If you've ever argued with your team about the way your JSON responses should be formatted, JSON API is your
41-
anti-bikeshedding weapon.
60+
> anti-bikeshedding weapon.
4261
>
43-
> By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus
44-
on what matters: your application. Clients built around JSON API are able to take advantage of its features around
45-
efficiently caching responses, sometimes eliminating network requests entirely.
62+
> By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus on
63+
> what matters: your application. Clients built around JSON API are able to take advantage of its features around
64+
> efficiently caching responses, sometimes eliminating network requests entirely.
4665
4766
For full information on the spec, plus examples, see [http://jsonapi.org](http://jsonapi.org).
4867

49-
## Tutorial and Documentation
50-
51-
Want a tutorial to get started? Read the
52-
[*How to JSON:API* Laravel tutorial.](https://howtojsonapi.com/laravel.html)
68+
## Documentation
5369

5470
Full package documentation is available on
5571
[Read the Docs](http://laravel-json-api.readthedocs.io/en/latest/).
5672

57-
## Demo
73+
## Slack
5874

59-
A demo application is available at [here](https://github.com/cloudcreativity/demo-laravel-json-api).
75+
Join the Laravel JSON:API community on
76+
[Slack.](https://join.slack.com/t/laraveljsonapi/shared_invite/zt-e3oi2r4y-8nkmhzpKnPQViaXrkPJHtQ)
6077

6178
## Laravel Versions
6279

@@ -73,12 +90,6 @@ A demo application is available at [here](https://github.com/cloudcreativity/dem
7390
Make sure you consult the [Upgrade Guide](http://laravel-json-api.readthedocs.io/en/latest/upgrade/)
7491
when upgrading between major or pre-release versions.
7592

76-
## Lumen
77-
78-
Currently we have not integrated the package with Lumen. We do not have any active projects that use Lumen,
79-
so if you do and can help, please let us know on
80-
[this issue](https://github.com/cloudcreativity/laravel-json-api/issues/61).
81-
8293
## License
8394

8495
Apache License (Version 2.0). Please see [License File](LICENSE) for more information.
@@ -89,8 +100,8 @@ Installation is via `composer`. See the documentation for complete instructions.
89100

90101
## Contributing
91102

92-
Contributions are absolutely welcome. Ideally submit a pull request, even more ideally with unit tests.
93-
Please note the following:
103+
Contributions are absolutely welcome. Ideally submit a pull request, even more ideally with unit tests. Please note the
104+
following:
94105

95106
- **Bug Fixes** - submit a pull request against the `master` branch.
96107
- **Enhancements / New Features** - submit a pull request against the `develop` branch.

database/migrations/2018_10_23_000001_create_client_jobs_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
/**
3-
* Copyright 2020 Cloud Creativity Limited
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

docs/basics/adapters.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ for Eloquent models. The relationship types available are `belongsTo`, `hasOne`,
233233
| `morphOne` | `hasOne` |
234234
| `morphMany` | `hasMany` |
235235
| `morphToMany` | `hasMany` |
236-
| `morphedByMany` | `morphMany` |
236+
| `morphedByMany` | `hasMany` |
237+
| n/a | `morphMany` |
237238
| n/a | `queriesOne` |
238239
| n/a | `queriesMany` |
239240

@@ -380,8 +381,8 @@ class Adapter extends AbstractAdapter
380381

381382
#### Morph-Many
382383

383-
Use the JSON API `morphMany` relation for an Eloquent `morphedByMany` relation. The `morphMany` relation in effect
384-
*mixes* multiple different JSON API resource relationships in a single relationship.
384+
Use the JSON API `morphMany` relation to *mix* multiple different JSON API resource relationships in a single
385+
relationship.
385386

386387
This is best demonstrated with an example. If our application has a `tags` resource that can be linked to either
387388
`videos` or `posts`, our `tags` adapter would define a `taggables` relation as follows:

docs/basics/routing.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ to it.
2222

2323
### API Route Prefix
2424

25-
When registering a JSON API, we automatically read the URL prefix and route name prefix from your
26-
[API's URL configuration](./api#url) and apply this to the route group for your API. The URL prefix in your JSON API
25+
When registering a JSON API, we automatically read the URL prefix and route name prefix from your
26+
[API's URL configuration](./api#url) and apply this to the route group for your API. The URL prefix in your JSON API
2727
config is **always** relative to the root URL on a host, i.e. from `/`.
2828
**This means when registering your routes, you need to ensure that no prefix has already been applied.**
2929

@@ -42,7 +42,7 @@ JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {
4242
```
4343

4444
> We use `withNamespace()` instead of Laravel's usual `namespace()` method because `namespace` is a
45-
[Reserved Keyword](http://php.net/manual/en/reserved.keywords.php).
45+
[Reserved Keyword](http://php.net/manual/en/reserved.keywords.php).
4646

4747
## Resource Routes
4848

@@ -67,6 +67,16 @@ JsonApi::register('default')->routes(function ($api) {
6767
});
6868
```
6969

70+
By default the resource type is used as the URI fragment: i.e. the `posts` resource will have a URI of
71+
`/posts`. If you want to use a different URI fragment, use the `uri()` method. In the following example,
72+
the resource type is `posts` but the URI will be `/blog_posts`:
73+
74+
```php
75+
JsonApi::register('default')->routes(function ($api) {
76+
$api->resource('posts')->uri('blog_posts');
77+
});
78+
```
79+
7080
## Relationship Routes
7181

7282
The JSON API spec also defines routes for relationships on a resource type. There are two types of relationships:
@@ -87,6 +97,19 @@ JsonApi::register('default')->routes(function ($api) {
8797
});
8898
```
8999

100+
By default the relationship name is used as the URI fragment: i.e. for the `comments` relationship on the
101+
`posts` resource, the related resource URI is `/posts/{record}/comments`. To customise the URI framgent,
102+
use the `uri()` method. In the following example, the relationship name is `comments` but the URI
103+
will be `/posts/{record}/blog_comments`:
104+
105+
```php
106+
JsonApi::register('default')->routes(function ($api) {
107+
$api->resource('posts')->relationships(function ($relations) {
108+
$relations->hasMany('comments')->uri('blog_comments');
109+
});
110+
});
111+
```
112+
90113
### Related Resource Type
91114

92115
When registering relationship routes, it is assumed that the resource type returned in the response is the
@@ -252,7 +275,7 @@ JsonApi::register('default')->withNamespace('Api')->routes(function ($api, $rout
252275

253276
### Controller Names
254277

255-
If you call `controller()` without any arguments, we assume your controller is the camel case name version of
278+
If you call `controller()` without any arguments, we assume your controller is the camel case name version of
256279
the resource type with `Controller` on the end. I.e. `posts` would expect `PostsController` and
257280
`blog-posts` would expect `BlogPostsController`. Or if your resource type was `post`,
258281
we would guess `PostController`.
@@ -332,7 +355,7 @@ If you are using these, you will also need to refer to the *Custom Actions* sect
332355

333356
Also note that custom routes are registered *before* the routes defined by the JSON API specification,
334357
i.e. those that are added when you call `$api->resource('posts')`. You will need to ensure that your
335-
custom route definitions do not collide with these defined routes.
358+
custom route definitions do not collide with these defined routes.
336359

337360
> Generally we advise against registering custom routes. This is because the JSON API specification may
338361
have additional routes added to it in the future, which might collide with your custom routes.
@@ -396,7 +419,7 @@ does not contain an `@` symbol we add the controller name to it.
396419

397420
Secondly, if you are defining a custom relationship route, you must use the `field` method. This takes
398421
the relationship name as its first argument. The inverse resource type can be specified as the second argument,
399-
for example:
422+
for example:
400423

401424
```php
402425
JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {

helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
/**
3-
* Copyright 2020 Cloud Creativity Limited
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

resources/lang/en/errors.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
/**
3-
* Copyright 2020 Cloud Creativity Limited
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

resources/lang/en/validation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
/**
3-
* Copyright 2020 Cloud Creativity Limited
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

resources/lang/fr/errors.php

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
return [
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Error Object Language Lines
23+
|--------------------------------------------------------------------------
24+
|
25+
| The following language lines contain the default translatable members
26+
| of JSON API error objects. According to the JSON API spec, the
27+
| `title` and `detail` members can be localized. In addition the `code`
28+
| member is also read from this package if you want to give the error
29+
| a specific code.
30+
|
31+
| Set any value to an empty string if you do not want the member to be
32+
| included in the error object.
33+
|
34+
| @see http://jsonapi.org/format/#errors
35+
*/
36+
37+
'unauthorized' => [
38+
'title' => 'Non authentifié',
39+
'detail' => '',
40+
'code' => '',
41+
],
42+
43+
'forbidden' => [
44+
'title' => 'Non autorisé',
45+
'detail' => '',
46+
'code' => '',
47+
],
48+
49+
'token_mismatch' => [
50+
'title' => 'Jeton invalide',
51+
'detail' => "Le jeton n'est pas valide.",
52+
'code' => '',
53+
],
54+
55+
'member_required' => [
56+
'title' => 'Document JSON API invalide',
57+
'detail' => 'Le membre :member est obligatoire.',
58+
'code' => '',
59+
],
60+
61+
'member_object_expected' => [
62+
'title' => 'Document JSON API invalide',
63+
'detail' => 'Le membre :member doit être un objet.',
64+
'code' => '',
65+
],
66+
67+
'member_identifier_expected' => [
68+
'title' => 'Document JSON API invalide',
69+
'detail' => 'Le membre :member doit être un identifiant de ressource.',
70+
'code' => '',
71+
],
72+
73+
'member_string_expected' => [
74+
'title' => 'Document JSON API invalide',
75+
'detail' => 'Le membre :member doit être une chaîne de caractères.',
76+
'code' => '',
77+
],
78+
79+
'member_empty' => [
80+
'title' => 'Document JSON API invalide',
81+
'detail' => 'Le membre :member ne peut être vide.',
82+
'code' => '',
83+
],
84+
85+
'member_field_not_allowed' => [
86+
'title' => 'Document JSON API invalide',
87+
'detail' => 'Le membre :member ne peut avoir de champ :field.',
88+
'code' => '',
89+
],
90+
91+
'resource_type_not_supported' => [
92+
'title' => 'Non supporté',
93+
'detail' => "Le type de ressource :type n'est pas supporté par ce endpoint.",
94+
'code' => '',
95+
],
96+
97+
'resource_type_not_recognised' => [
98+
'title' => 'Non supporté',
99+
'detail' => "Le type de ressource :type n'est pas reconnu.",
100+
'code' => '',
101+
],
102+
103+
'resource_id_not_supported' => [
104+
'title' => 'Non supporté',
105+
'detail' => "L'identifiant de ressource :id n'est pas supporté par ce endpoint.",
106+
'code' => '',
107+
],
108+
109+
'resource_client_ids_not_supported' => [
110+
'title' => 'Non supporté',
111+
'detail' => "Le type de ressource :type n'accepte pas les identifiants générés par le client.",
112+
'code' => '',
113+
],
114+
115+
'resource_exists' => [
116+
'title' => 'Conflit',
117+
'detail' => 'La ressource :id existe déjà.',
118+
'code' => '',
119+
],
120+
121+
'resource_not_found' => [
122+
'title' => 'Introuvable',
123+
'detail' => "La ressource spécifiée n'existe pas.",
124+
'code' => '',
125+
],
126+
127+
'resource_field_exists_in_attributes_and_relationships' => [
128+
'title' => "Document JSON API invalide",
129+
'detail' => 'Le champ :field ne peut être à la fois un attribut et une relation.',
130+
'code' => '',
131+
],
132+
133+
'resource_invalid' => [
134+
'title' => 'Entité non traitable',
135+
'detail' => 'Le document est correctement structuré mais contient des erreurs sémantiques.',
136+
'code' => '',
137+
],
138+
139+
'resource_cannot_be_deleted' => [
140+
'title' => 'Non supprimable',
141+
'detail' => 'La ressource ne peut être supprimée.',
142+
'code' => '',
143+
],
144+
145+
'query_invalid' => [
146+
'title' => 'Paramètre de requête invalide',
147+
'detail' => 'Les paramètres de la requête ne sont pas valides.',
148+
'code' => '',
149+
],
150+
151+
'failed_validator' => [
152+
'title' => 'Entité non traitable',
153+
'detail' => 'Le document est correctement structuré mais contient des erreurs sémantiques.',
154+
'code' => '',
155+
],
156+
];

0 commit comments

Comments
 (0)