8000 [Feature] Add `isCreatingOrUpdating` request helper method · X-Coder264/laravel@c8d88b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8d88b7

Browse files
committed
[Feature] Add isCreatingOrUpdating request helper method
1 parent 684933b commit c8d88b7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file. This projec
1111
actions were authorized via the single `showRelationship()` method. Adding the new `showRelated` method means
1212
developers can now implement separate authorization logic for these two actions if desired. Our default implementation
1313
remains unchanged - both are authorized using the `view<RelationshipName>` method on the relevant policy.
14+
- The request class now has a `isCreatingOrUpdating()` helper method to determine whether the request is to create or
15+
updated a resource.
1416

1517
## [1.0.0-beta.4] - 2021-06-02
1618

src/Http/Requests/FormRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ public function isUpdating(): bool
125125
return $this->isMethod('PATCH') && $this->isNotRelationship();
126126
}
127127

128+
/**
129+
* Is this a request to create or update a resource?
130+
*
131+
* @return bool
132+
*/
133+
public function isCreatingOrUpdating(): bool
134+
{
135+
return $this->isCreating() || $this->isUpdating();
136+
}
137+
128138
/**
129139
* Is this a request to replace a resource relationship?
130140
*

src/Http/Requests/ResourceRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function validatedForRelation()
238238
*/
239239
protected function prepareForValidation()
240240
{
241-
if ($this->isCreating() || $this->isUpdating()) {
241+
if ($this->isCreatingOrUpdating()) {
242242
$this->assertSupportedMediaType();
243243
$this->validateResourceDocument();
244244
} else if ($this->isModifyingRelationship()) {

0 commit comments

Comments
 (0)
0