ldc-legaulois/app/Http/Requests/Club/Customers/UpdateCustomerRequest.php

52 lines
1.4 KiB
PHP

<?php
namespace App\Http\Requests\Club\Customers;
use App\Http\Requests\Club\Customers\StoreCustomerRequest;
use Illuminate\Support\Facades\Auth;
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(),
'email' => auth()->user()->email,
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return array_merge(parent::rules(), [
'password' => 'nullable',
'question_id' => 'required|integer',
'answers' => 'present|array',
'answers.*' => 'integer|min:0',
'email' => 'required|email:rfc,dns,spoof|max:255|exists:customers,email',
]);
}
}