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

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

edited file upload, seeding and departments controller

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[24a616f]1<?php
2
3namespace App\Http\Requests\Dashboard;
4
[e6c1f87]5use App\Models\Department;
[24a616f]6use App\Models\Document;
[d795fa6]7use App\Models\FileType;
[24a616f]8use Illuminate\Foundation\Http\FormRequest;
9
10class DocumentRequest 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 {
[bd9e8e3]19 if ($this->isMethod("patch")) {
[24a616f]20 $document = Document::find($this->route("id"));
21 return auth()->user()->hasPermission("edit_all_documents") || ($document->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 {
[d795fa6]34
[24a616f]35 $rules = [
[bd9e8e3]36 "arch_id" => [
37 "required",
[b9c4a92]38 function ($attribute, $value, $fail) {
[bd9e8e3]39 $arch_id = $this->request->get('arch_id');
40 $deptId = explode('/', $arch_id)[0];
[b9c4a92]41 $archNum = explode('/', $arch_id)[1];
42
43 if (empty($archNum)) {
44 $fail("Please enter documents Archive ID");
45 }
46
[e6c1f87]47 if ($deptId !== Department::find($this->request->get('department'))->code) {
48 $fail("Document Archive ID field format is invalid");
[bd9e8e3]49 }
50 }
51 ],
[24a616f]52 "name" => "required|min:10|max:255",
53 "department" => "required|integer|exists:departments,id",
54 "description" => "required|min:30",
55 ];
56
[bd9e8e3]57 if ($this->isMethod("patch")) {
[24a616f]58 $fileRules = [
59 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
[bd9e8e3]60 ];
[24a616f]61 } else {
62 $fileRules = [
63 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
64 ];
65 }
66
67 $rules = array_merge(
68 $rules,
69 $fileRules,
70 );
71
72 return $rules;
73 }
74}
Note: See TracBrowser for help on using the repository browser.