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
RevLine 
[24a616f]1<?php
2
3namespace App\Http\Requests\Dashboard;
4
[e6c1f87]5use App\Models\Department;
[24a616f]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 {
[bd9e8e3]18 if ($this->isMethod("patch")) {
[24a616f]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 = [
[bd9e8e3]34 "arch_id" => [
35 "required",
[b9c4a92]36 function ($attribute, $value, $fail) {
[bd9e8e3]37 $arch_id = $this->request->get('arch_id');
38 $deptId = explode('/', $arch_id)[0];
[b9c4a92]39 $archNum = explode('/', $arch_id)[1];
40
41 if (empty($archNum)) {
42 $fail("Please enter documents Archive ID");
43 }
44
[e6c1f87]45 if ($deptId !== Department::find($this->request->get('department'))->code) {
46 $fail("Document Archive ID field format is invalid");
[bd9e8e3]47 }
48 }
49 ],
[24a616f]50 "name" => "required|min:10|max:255",
51 "department" => "required|integer|exists:departments,id",
52 "description" => "required|min:30",
53 ];
54
[bd9e8e3]55 if ($this->isMethod("patch")) {
[24a616f]56 $fileRules = [
[ea7b12a]57 "file_item.*" => "mimes:jpg,jpeg,png,pdf|max:4096"
[bd9e8e3]58 ];
[24a616f]59 } else {
60 $fileRules = [
[ea7b12a]61 "file_item.*" => "mimes:jpg,jpeg,png,pdf|max:4096"
[24a616f]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.