1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Requests; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
6
|
|
|
|
7
|
|
|
class TransactionRequest extends FormRequest |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Determine if the user is authorized to make this request. |
11
|
|
|
* |
12
|
|
|
* @return bool |
13
|
|
|
*/ |
14
|
|
|
public function authorize() |
15
|
|
|
{ |
16
|
|
|
return true; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get the validation rules that apply to the request. |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
public function rules() |
25
|
|
|
{ |
26
|
|
|
$size = $this->getMaxFileUploadSizeInKb(); |
27
|
|
|
|
28
|
|
|
return [ |
29
|
|
|
'transaction_date' => 'date_format:'.locale_dateformat().'|nullable', |
30
|
|
|
'transaction_status' => 'integer', |
31
|
|
|
'transaction_type' => 'required|integer', |
32
|
|
|
'account' => 'required|integer', |
33
|
|
|
'to_account' => 'sometimes|required|integer', |
34
|
|
|
'payee' => 'sometimes|required|integer', |
35
|
|
|
'category' => 'required|integer', |
36
|
|
|
'subcategory' => 'integer', |
37
|
|
|
'amount' => 'required|numeric', |
38
|
|
|
'amount' => 'required|numeric|min:0|max:999999', |
39
|
|
|
'attachments.*' => 'max:'.$size, |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function getMaxFileUploadSizeInKb() |
44
|
|
|
{ |
45
|
|
|
$uploadSizes = [ini_get('upload_max_filesize'), ini_get('post_max_size')]; |
46
|
|
|
|
47
|
|
|
$uploadSizes = array_map(function ($item) { |
48
|
|
|
$metric = strtoupper(substr($item, -1)); |
49
|
|
|
|
50
|
|
|
switch ($metric) { |
51
|
|
|
case 'K': |
52
|
|
|
return (int) $item * 1024; |
53
|
|
|
case 'M': |
54
|
|
|
return (int) $item * 1048576; |
55
|
|
|
case 'G': |
56
|
|
|
return (int) $item * 1073741824; |
57
|
|
|
default: |
58
|
|
|
return (int) $item; |
59
|
|
|
} |
60
|
|
|
}, $uploadSizes); |
61
|
|
|
|
62
|
|
|
return min($uploadSizes) * 1024; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|