source: app/Http/Requests/Dashboard/FolderRequest.php@ c6b84df

develop
Last change on this file since c6b84df was c6b84df, checked in by beratkjufliju <kufliju@…>, 3 years ago

added fileTypes controller, notifications, excel export, edited views

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[c6b84df]1<?php
2
3namespace App\Http\Requests\Dashboard;
4
5use App\Models\Department;
6use App\Models\FileType;
7use App\Models\Folder;
8use Illuminate\Foundation\Http\FormRequest;
9
10class FolderRequest extends FormRequest
11{
12 /**
13 * Determine if the user is authorized to make this request.
14 *
15 * @return bool
16 */
17 public function authorize()
18 {
19 if ($this->isMethod("patch")) {
20 $folder = Folder::find($this->route("id"));
21 return auth()->user()->hasPermission("edit_all_folders") || ($folder->user->id == auth()->user()->id);
22 }
23
24 return true;
25 }
26
27 /**
28 * Get the validation rules that apply to the request.
29 *
30 * @return array
31 */
32 public function rules()
33 {
34 $rules = [
35 "arch_id" => [
36 "required",
37 "unique:folders,arch_id,$this->id,id",
38 function ($attribute, $value, $fail) {
39
40 try {
41 $arch_id = $this->request->get('arch_id');
42
43 $deptId = explode('/', $arch_id)[0];
44 $archNum = explode('/', $arch_id)[1];
45
46 if (empty($archNum)) {
47 $fail("Please enter folders Archive ID");
48 }
49
50 if ($deptId !== Department::find($this->request->get('department'))->code) {
51 $fail("Folder Archive ID field format is invalid");
52 }
53 } catch (\Exception $e) {
54 $fail("Please enter folders Archive ID");
55 }
56 }
57 ],
58 "name" => "required|min:2|max:30",
59 "department" => "required|integer|exists:departments,id",
60 ];
61
62 $mimes = FileType::find("1")->mimes;
63 $maxSize = FileType::find("1")->max_size;
64
65 if ($this->isMethod("patch")) {
66 $fileRules = [
67 "file_item.*" => "mimes:{$mimes}|max:{$maxSize}"
68 ];
69 }
70
71 else {
72 $fileRules = [
73 "file_item.*" => "mimes:{$mimes}|max:{$maxSize}"
74 ];
75 }
76
77 $rules = array_merge(
78 $rules,
79 $fileRules,
80 );
81
82 return $rules;
83 }
84}
Note: See TracBrowser for help on using the repository browser.