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

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

added arch_id validation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[24a616f]1<?php
2
3namespace App\Http\Requests\Dashboard;
4
5use App\Models\Document;
[d795fa6]6use App\Models\FileType;
[24a616f]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 {
[d795fa6]33
[24a616f]34 $rules = [
[bd9e8e3]35 "arch_id" => [
36 "required",
37 function($attribute, $value, $fail) {
38 $arch_id = $this->request->get('arch_id');
39 $deptId = explode('/', $arch_id)[0];
40 if ($deptId !== $this->request->get('department')) {
41 $fail("Dept id error");
42 }
43 }
44 ],
[24a616f]45 "name" => "required|min:10|max:255",
46 "department" => "required|integer|exists:departments,id",
47 "description" => "required|min:30",
48 ];
49
[bd9e8e3]50 if ($this->isMethod("patch")) {
[24a616f]51 $fileRules = [
52 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
[bd9e8e3]53 ];
[24a616f]54 } else {
55 $fileRules = [
56 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
57 ];
58 }
59
60 $rules = array_merge(
61 $rules,
62 $fileRules,
63 );
64
65 return $rules;
66 }
67}
Note: See TracBrowser for help on using the repository browser.