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

38 lines
925 B
PHP
Raw Normal View History

2021-04-18 20:31:07 +02:00
<?php
namespace App\Http\Requests;
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
]);
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-05-04 17:41:39 +02:00
'message' => 'required|min:' . (auth()->user()->role == 1 ? '5' : '20'),
2021-04-18 20:31:07 +02:00
'file_message' => 'sometimes|mimes:jpeg,jpg,png,pdf|max:2048'
];
}
}