63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api\V4;
|
|
|
|
use App\Enums\Country;
|
|
use App\Http\Sanitizers\RemoveSpaces;
|
|
use ArondeParon\RequestSanitizer\Sanitizers\Capitalize;
|
|
use ArondeParon\RequestSanitizer\Sanitizers\Lowercase;
|
|
use ArondeParon\RequestSanitizer\Sanitizers\Trim;
|
|
use ArondeParon\RequestSanitizer\Sanitizers\TrimDuplicateSpaces;
|
|
|
|
class SendClaimRequest extends BaseApiRequest
|
|
{
|
|
/**
|
|
* Using these sanitizers before proceeding the request.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $sanitizers = [
|
|
'first_name' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
|
|
'last_name' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
|
|
'email' => [Trim::class, RemoveSpaces::class, Lowercase::class],
|
|
'address' => [Trim::class, TrimDuplicateSpaces::class],
|
|
'city' => [Trim::class, TrimDuplicateSpaces::class],
|
|
'postcode' => [Trim::class],
|
|
'file' => [Trim::class],
|
|
'message' => [Trim::class],
|
|
];
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$countryList = ($this->currentCountry && $this->currentCountry->get('iso')) ?
|
|
$this->currentCountry->get('iso') : implode(',', Country::getValidIsoAplha2Codes());
|
|
return [
|
|
'first_name' => 'required|string|between:3,255',
|
|
'last_name' => 'required|string|between:3,255',
|
|
'email' => 'required|email:rfc,dns,spoof,filter|max:255',
|
|
'address' => 'sometimes|nullable|string|max:255',
|
|
'city' => 'sometimes|nullable|string|between:2,255',
|
|
'postcode' => ['sometimes', 'nullable', 'string', "postal_code:{$countryList}"],
|
|
'file' => 'sometimes|nullable|mimes:jpg,jpeg,png,pdf|max:5120',
|
|
'message' => 'required|string|min:3',
|
|
'brand_id' => 'required|integer|exists:brands,id',
|
|
'subject_id' => 'required|integer|exists:claim_subjects,id',
|
|
'customer_id' => 'sometimes|nullable|integer|exists:customers,id',
|
|
];
|
|
}
|
|
}
|