Skip to content

Instantly share code, notes, and snippets.

@kokamvd
Created October 17, 2022 08:50
Show Gist options
  • Save kokamvd/a02047a7d12798baa5b9e39e7ea56d14 to your computer and use it in GitHub Desktop.
Save kokamvd/a02047a7d12798baa5b9e39e7ea56d14 to your computer and use it in GitHub Desktop.
ExampleValidationException
<?php
namespace App\Containers\AppSection\Branch\Exceptions;
use App\Ship\Parents\Exceptions\ValidationException as ParentValidationException;
class ExampleValidationException extends ParentValidationException
{
protected string $scope = 'E_EXAMPLE';
protected string $textCode = 'E_EXAMPLE_TEXT_CODE';
protected ?string $text = 'Example exception message text or localization key';
}
<?php
namespace App\Containers\AppSection\Branch\UI\API\Requests;
use App\Containers\AppSection\Branch\Exceptions\ExampleValidationException;
use App\Ship\Parents\Requests\Request as ParentRequest;
use Illuminate\Support\Facades\Auth;
class FillBranchRequest extends ParentRequest
{
public const ID = 'id';
public const NAME = 'name';
public const URL = 'url';
public const TYPE = 'type';
public const LOCAL_API_URL = 'localApiUrl';
protected array $validationExceptions = [
self::URL => ExampleValidationException::class,
];
public function authorize(): bool
{
return Auth::check();
}
protected function prepareForValidation()
{
if ($name = $this->route()->parameter('name')) {
$this->mergeIfMissing(['name' => $name]);
}
$this->merge([self::LOCAL_API_URL => $this->getContent()]);
}
public function rules(): array
{
return [
self::URL => [
'required',
'url',
],
self::LOCAL_API_URL => [
'string',
],
self::NAME => [
'string',
],
];
}
public function getName(): string
{
return $this->route(self::NAME);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment