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

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

added validation to blades

  • Property mode set to 100644
File size: 1.3 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 {
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 {
[d795fa6]33
[24a616f]34 $rules = [
35 "arch_id" => "required|min:10|max:255",
36 "name" => "required|min:10|max:255",
37 "department" => "required|integer|exists:departments,id",
38 "description" => "required|min:30",
39 ];
40
41 if($this->isMethod("patch")) {
42 $fileRules = [
43 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
[d795fa6]44 ];
[24a616f]45 } else {
46 $fileRules = [
47 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
48 ];
49 }
50
51 $rules = array_merge(
52 $rules,
53 $fileRules,
54 );
55
56 return $rules;
57 }
58}
Note: See TracBrowser for help on using the repository browser.