ldc-supportweb/app/Http/Requests/CreateMessage.php

56 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-04-18 20:31:07 +02:00
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateMessage extends FormRequest
{
2021-05-18 20:07:42 +02:00
/**
* Determine if the user is authorized to make this request.
*
2022-03-29 16:57:54 +02:00
* @return boolean
2021-05-18 20:07:42 +02:00
*/
public function authorize()
{
/** @var \App\Models\User|null */
if (!($user = auth()->user())) {
return false;
}
return auth()->check() and auth()->user()->sites and (
$user->isAdmin() or
auth()->user()->sites->contains(request()->route()->ticket->site_id)
);
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
2021-05-18 20:07:42 +02:00
$this->merge([
'subscribe' => $this->subscribe ? true : false
]);
}
2021-04-18 20:31:07 +02:00
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2021-07-23 11:04:09 +02:00
/** @var \App\Models\User */
$user = auth()->user();
2021-04-18 20:31:07 +02:00
return [
2021-05-18 20:07:42 +02:00
'subscribe' => 'required|boolean',
2021-07-23 11:04:09 +02:00
'message' => 'required|min:' . ($user->isAdmin() ? '5' : '20'),
2021-04-18 20:31:07 +02:00
'file_message' => 'sometimes|mimes:jpeg,jpg,png,pdf|max:2048'
];
}
}