48 lines
1,020 B
PHP
48 lines
1,020 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Bo\Ajax;
|
||
|
|
|
||
|
|
use App\Enums\ContactType;
|
||
|
|
use App\Rules\EnumIsValidRule;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class SendContactMessageRequest extends FormRequest
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*
|
||
|
|
* @return boolean
|
||
|
|
*/
|
||
|
|
public function authorize()
|
||
|
|
{
|
||
|
|
return auth()->check() and $this->ajax();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Prepare the data for validation.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
protected function prepareForValidation()
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'url' => strval($this->url),
|
||
|
|
'type' => intval($this->type)
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function rules()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'type' => ['required', new EnumIsValidRule(ContactType::class)],
|
||
|
|
'url' => 'nullable|url',
|
||
|
|
'message' => 'required|string|min:20'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|