ldc-legaulois/app/Http/Requests/Club/Customers/UpdateCustomerRequest.php
2024-10-08 11:57:56 +02:00

56 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests\Club\Customers;
use App\Http\Requests\Club\Customers\StoreCustomerRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class UpdateCustomerRequest extends StoreCustomerRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Auth::guard('club')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
public function prepareForValidation(): void
{
parent::prepareForValidation();
$this->merge([
'question_id' => intval($this->input('question_id')),
'answers' => collect($this->input('answers'))->map(function (string $value) {
return intval($value);
})->toArray(),
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return array_merge(parent::rules(), [
'email' => [
'required',
'email:rfc,strict,dns,spoof,filter',
Rule::unique('users', 'email')->ignore(\optional($this->route('user'))->getRouteKey())
],
'password' => 'nullable',
'question_id' => 'required|integer',
'answers' => 'present|array',
'answers.*' => 'integer|min:0',
]);
}
}