source: app/Http/Requests/Dashboard/DocumentRequest.php@ ea7b12a

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

added files crud in table

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