2021-04-18 20:31:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
2021-06-18 15:39:19 +02:00
|
|
|
use App\Enums\Role;
|
2021-04-18 20:31:07 +02:00
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function authorize()
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'subscribe' => $this->subscribe ? true : false
|
|
|
|
|
]);
|
2021-06-18 15:39:19 +02:00
|
|
|
return auth()->check() and (auth()->user()->role->equals(Role::admin()) or
|
2021-05-18 20:07:42 +02:00
|
|
|
$this->ticket->project->id === auth()->user()->project_id);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 20:31:07 +02:00
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2021-05-18 20:07:42 +02:00
|
|
|
'subscribe' => 'required|boolean',
|
2021-06-21 12:57:34 +02:00
|
|
|
'message' => 'required|min:' . (auth()->user()->role->equals(Role::admin()) ? '5' : '20'),
|
2021-04-18 20:31:07 +02:00
|
|
|
'file_message' => 'sometimes|mimes:jpeg,jpg,png,pdf|max:2048'
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|