Skip to content

Commit

Permalink
Validation were throwing error when we pass a bad formated rules array
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-falcon committed Nov 19, 2020
1 parent 6ec2636 commit 80a41c5
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/PendingTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationException;

class PendingTrigger
{
Expand All @@ -24,20 +21,25 @@ public function __construct(Task $task)

public function withValid(array $data): self
{
$validator = Validator::make(
$data,
$this->task->rules(),
$this->task->messages(),
$this->task->customAttributes()
);

if ($validator->fails()) {
try {
$validator = Validator::make(
$data,
$this->task->rules(),
$this->task->messages(),
$this->task->customAttributes()
);

if ($validator->fails()) {
$this->error = true;
$this->task->validationError($validator);
}

$this->task->validated($validator->validated());
} catch (\BadMethodCallException $exception) {
$this->error = true;
$this->task->validationError($validator);
throw $exception;
}

$this->task->validated($validator->validated());

return $this;
}

Expand All @@ -53,6 +55,13 @@ public function forceResult()
return $this->execute();
}

private function execute()
{
$this->executed = true;

return app()->call([$this->task, 'handle']);
}

public function __destruct()
{
if ($this->executed === false && $this->error === false) {
Expand All @@ -67,13 +76,6 @@ public function result()
return $this->execute();
}

private function execute()
{
$this->executed = true;

return app()->call([$this->task, 'handle']);
}

private function resolveAuthorization(): void
{
if (method_exists($this->task, 'authorize')) {
Expand Down

0 comments on commit 80a41c5

Please sign in to comment.