96 lines
2.8 KiB
PHP
96 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Fo;
|
|
|
|
use App\Http\Requests\Fo\Customers\CreateAccountRequest;
|
|
use App\Repositories\Fo\CrmRepository;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use LDC\LDCCRM\Enums\Country;
|
|
|
|
class SubmitWinningProofRequest extends CreateAccountRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return auth('frontend')->check() && Gate::check('submitProof', $this->route('participation'));
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$authUser = auth('frontend')->user();
|
|
$countryCode = $this->integer('country') != 0 ?
|
|
$this->integer('country') : ($authUser ?
|
|
new CrmRepository()->fetchCrmCustomer($authUser)->country->value : 0);
|
|
$countryRules = match ($countryCode) {
|
|
Country::belgium->value => ['phone' => 'phone:BE'],
|
|
Country::luxembourg->value => ['phone' => 'phone:LU'],
|
|
Country::germany->value => ['phone' => 'phone:DE'],
|
|
default => ['phone' => 'phone:FR'],
|
|
};
|
|
|
|
return \array_merge(
|
|
Arr::only(
|
|
parent::rules(),
|
|
[
|
|
'lastname',
|
|
'firstname',
|
|
'address',
|
|
'address2',
|
|
'postal_code',
|
|
'city',
|
|
'country',
|
|
]
|
|
),
|
|
[
|
|
'phone' => [
|
|
'required',
|
|
'max:255',
|
|
$countryRules['phone'],
|
|
],
|
|
],
|
|
$this->proofRules()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Rules of winning proof.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
private function proofRules(): array
|
|
{
|
|
// * Min 10 KB, Max 2MB
|
|
$fileRules = 'required|mimes:jpeg,jpg,png,pdf|min:10|max:2048';
|
|
|
|
return collect(['sticker', 'ticket', 'barcode'])
|
|
->filter(fn (string $proof) => config("proofs.$proof"))
|
|
->mapWithKeys(fn (string $proof): array => [$proof => $fileRules])
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return \array_merge(
|
|
parent::attributes(),
|
|
[
|
|
'sticker' => trans('validation.custom.sticker'),
|
|
'ticket' => trans('validation.custom.ticket'),
|
|
'barcode' => trans('validation.custom.barcode'),
|
|
]
|
|
);
|
|
}
|
|
}
|