1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Http\Requests; |
13
|
|
|
|
14
|
|
|
use Tinyissue\Form\FormInterface; |
15
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Request is an abstract class for Form Request classes. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class Request extends FormRequest |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* An instance of Form. |
26
|
|
|
* |
27
|
|
|
* @var FormInterface |
28
|
|
|
*/ |
29
|
|
|
protected $form; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class name of the form. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $formClassName; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Set the instance of the form. |
40
|
|
|
* |
41
|
|
|
* @param FormInterface $form |
42
|
|
|
* |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
27 |
|
public function setForm(FormInterface $form) |
46
|
|
|
{ |
47
|
27 |
|
$this->form = $form; |
48
|
|
|
|
49
|
27 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns an instance of the form. |
54
|
|
|
* |
55
|
|
|
* @return FormInterface |
56
|
|
|
*/ |
57
|
27 |
|
public function getForm() |
58
|
|
|
{ |
59
|
27 |
|
return $this->form; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the class name of the form. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
27 |
|
public function getFormClassName() |
68
|
|
|
{ |
69
|
27 |
|
return $this->formClassName; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
27 |
|
public function rules() |
76
|
|
|
{ |
77
|
27 |
|
return $this->getForm()->rules(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
23 |
|
public function authorize() |
84
|
|
|
{ |
85
|
|
|
// Only allow logged in users |
86
|
23 |
|
return \Auth::check(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $errors |
91
|
|
|
* |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
3 |
|
public function response(array $errors) |
95
|
|
|
{ |
96
|
3 |
|
return parent::response($errors)->with('notice-error', trans('tinyissue.we_have_some_errors')); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
1 |
|
protected function getRedirectUrl() |
103
|
|
|
{ |
104
|
1 |
|
return $this->getForm()->getRedirectUrl(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: