Skip to content

Commit 0fbbdd8

Browse files
committed
[Feature] Update to cloudcreativity/laravel-json-api 0.5.x-dev
1 parent bbd8c32 commit 0fbbdd8

File tree

10 files changed

+77
-66
lines changed

10 files changed

+77
-66
lines changed

app/Http/Controllers/Api/PeopleController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ final class PeopleController extends EloquentController
1111

1212
/**
1313
* PeopleController constructor.
14-
* @param People\Request $request
1514
* @param People\Hydrator $hydrator
1615
*/
17-
public function __construct(
18-
People\Request $request,
19-
People\Hydrator $hydrator
20-
) {
21-
parent::__construct(new Person(), $request, $hydrator);
16+
public function __construct(People\Hydrator $hydrator)
17+
{
18+
parent::__construct(new Person(), $hydrator);
19+
}
20+
21+
/**
22+
* @return string
23+
*/
24+
protected function getRequestHandler()
25+
{
26+
return People\Request::class;
2227
}
2328

2429
}

app/Http/Controllers/Api/PostsController.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ class PostsController extends EloquentController
1111

1212
/**
1313
* PostsController constructor.
14-
* @param Posts\Request $request
1514
* @param Posts\Hydrator $hydrator
1615
* @param Posts\Search $search
1716
*/
18-
public function __construct(
19-
Posts\Request $request,
20-
Posts\Hydrator $hydrator,
21-
Posts\Search $search
22-
) {
23-
parent::__construct(new Post(), $request, $hydrator, $search);
17+
public function __construct(Posts\Hydrator $hydrator, Posts\Search $search)
18+
{
19+
parent::__construct(new Post(), $hydrator, $search);
20+
}
21+
22+
/**
23+
* @return string
24+
*/
25+
protected function getRequestHandler()
26+
{
27+
return Posts\Request::class;
2428
}
2529
}

app/JsonApi/Comments/Schema.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ class Schema extends EloquentSchema
1111

1212
const RESOURCE_TYPE = 'comments';
1313

14-
/**
15-
* @var string
16-
*/
17-
protected $resourceType = self::RESOURCE_TYPE;
18-
1914
/**
2015
* @var array
2116
*/
2217
protected $attributes = [
2318
'content'
2419
];
2520

21+
/**
22+
* @return string
23+
*/
24+
public function getResourceType()
25+
{
26+
return self::RESOURCE_TYPE;
27+
}
28+
2629
/**
2730
* @param object $resource
2831
* @param bool $isPrimary

app/JsonApi/People/Hydrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Person;
66
use CloudCreativity\JsonApi\Contracts\Object\StandardObjectInterface;
7-
use CloudCreativity\LaravelJsonApi\Hydrator\AbstractHydrator;
7+
use CloudCreativity\JsonApi\Hydrator\AbstractHydrator;
88

99
class Hydrator extends AbstractHydrator
1010
{

app/JsonApi/People/Request.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
namespace App\JsonApi\People;
44

5-
use CloudCreativity\LaravelJsonApi\Http\Requests\AbstractRequest;
5+
use CloudCreativity\LaravelJsonApi\Http\Requests\AbstractRequestHandler;
66

7-
class Request extends AbstractRequest
7+
class Request extends AbstractRequestHandler
88
{
99

10-
/**
11-
* @var string
12-
*/
13-
protected $resourceType = Schema::RESOURCE_TYPE;
14-
1510
/**
1611
* @var array
1712
*/
1813
protected $allowedFilteringParameters = [
1914
'id',
2015
];
2116

17+
/**
18+
* @return string
19+
*/
20+
public function getResourceType()
21+
{
22+
return Schema::RESOURCE_TYPE;
23+
}
24+
2225
}

app/JsonApi/People/Schema.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ class Schema extends EloquentSchema
1111

1212
const RESOURCE_TYPE = 'people';
1313

14-
/**
15-
* @var string
16-
*/
17-
protected $resourceType = self::RESOURCE_TYPE;
18-
1914
/**
2015
* @var array
2116
*/
@@ -24,6 +19,14 @@ class Schema extends EloquentSchema
2419
'surname',
2520
];
2621

22+
/**
23+
* @return string
24+
*/
25+
public function getResourceType()
26+
{
27+
return self::RESOURCE_TYPE;
28+
}
29+
2730
/**
2831
* @param object $resource
2932
* @param bool $isPrimary

app/JsonApi/Posts/Hydrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use CloudCreativity\JsonApi\Contracts\Object\RelationshipInterface;
88
use CloudCreativity\JsonApi\Contracts\Object\StandardObjectInterface;
99
use CloudCreativity\JsonApi\Exceptions\HydratorException;
10-
use CloudCreativity\LaravelJsonApi\Hydrator\AbstractHydrator;
10+
use CloudCreativity\JsonApi\Hydrator\AbstractHydrator;
1111

1212
class Hydrator extends AbstractHydrator
1313
{

app/JsonApi/Posts/Request.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33
namespace App\JsonApi\Posts;
44

5-
use CloudCreativity\LaravelJsonApi\Http\Requests\AbstractRequest;
5+
use CloudCreativity\LaravelJsonApi\Http\Requests\AbstractRequestHandler;
66

7-
class Request extends AbstractRequest
7+
class Request extends AbstractRequestHandler
88
{
99

10-
/**
11-
* @var string
12-
*/
13-
protected $resourceType = Schema::RESOURCE_TYPE;
14-
1510
/**
1611
* @var array
1712
*/
@@ -51,7 +46,15 @@ class Request extends AbstractRequest
5146
*/
5247
public function __construct(Validators $validator)
5348
{
54-
parent::__construct($validator);
49+
parent::__construct(null, $validator);
50+
}
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getResourceType()
56+
{
57+
return Schema::RESOURCE_TYPE;
5558
}
5659

5760
}

app/JsonApi/Posts/Schema.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ class Schema extends EloquentSchema
1111

1212
const RESOURCE_TYPE = 'posts';
1313

14-
/**
15-
* @var string
16-
*/
17-
protected $resourceType = self::RESOURCE_TYPE;
18-
1914
/**
2015
* @var array
2116
*/
@@ -25,6 +20,14 @@ class Schema extends EloquentSchema
2520
'content',
2621
];
2722

23+
/**
24+
* @return string
25+
*/
26+
public function getResourceType()
27+
{
28+
return self::RESOURCE_TYPE;
29+
}
30+
2831
/**
2932
* @param object $resource
3033
* @param bool $isPrimary

app/JsonApi/Posts/Validators.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,17 @@
55
use App\Post;
66
use CloudCreativity\JsonApi\Contracts\Validators\RelationshipsValidatorInterface;
77
use CloudCreativity\LaravelJsonApi\Validators\AbstractValidatorProvider;
8-
use Illuminate\Contracts\Validation\Validator;
98

109
class Validators extends AbstractValidatorProvider
1110
{
1211

1312
/**
14-
* @var string
13+
* @inheritdoc
1514
*/
16-
protected $resourceType = Schema::RESOURCE_TYPE;
17-
18-
/**
19-
* Get the rules to validate the attributes.
20-
*
21-
* @param Post|null $record
22-
* the record being updated, or null if one is being created.
23-
* @return array
24-
*/
25-
protected function attributeRules($record = null)
15+
protected function attributeRules($resourceType, $record = null)
2616
{
17+
/** @var Post $record */
18+
2719
// The JSON API spec says the client does not have to send all attributes for an update request, so
2820
// if the record already exists we need to include a 'sometimes' before required.
2921
$required = $record ? 'sometimes|required' : 'required';
@@ -41,22 +33,17 @@ protected function attributeRules($record = null)
4133
}
4234

4335
/**
44-
* Define the rules to validate relationships.
45-
*
46-
* @param RelationshipsValidatorInterface $relationships
47-
* @param Post|null $record
36+
* @inheritdoc
4837
*/
49-
protected function relationshipRules(RelationshipsValidatorInterface $relationships, $record = null)
38+
protected function relationshipRules(RelationshipsValidatorInterface $relationships, $resourceType, $record = null)
5039
{
5140
$relationships->hasOne('author', 'people', is_null($record), false);
5241
}
5342

5443
/**
55-
* Define the rules to validate the filter query param.
56-
*
57-
* @return array
44+
* @inheritdoc
5845
*/
59-
protected function filterRules()
46+
protected function filterRules($resourceType)
6047
{
6148
return [
6249
'title' => 'string|min:1',

0 commit comments

Comments
 (0)