質問編集履歴

1

FormRequestの関連しそうなメソッドを提示

2018/05/14 06:59

投稿

workr
workr

スコア158

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,55 @@
21
21
 
22
22
 
23
23
  一時的に遷移先を変えたいだけであっても、もととなる FormRequest クラスを extends し、failedValidation() か getRedirectUrl() をオーバーライドした FormRequest クラスをフォームごとに用意する他ないのでしょうか?
24
+
25
+
26
+
27
+ Illuminate\Foundation\Http\FormRequest
28
+
29
+
30
+
31
+ ```php
32
+
33
+ protected function failedValidation(Validator $validator)
34
+
35
+ {
36
+
37
+ throw (new ValidationException($validator))
38
+
39
+ ->errorBag($this->errorBag)
40
+
41
+ ->redirectTo($this->getRedirectUrl());
42
+
43
+ }
44
+
45
+
46
+
47
+ protected function getRedirectUrl()
48
+
49
+ {
50
+
51
+ $url = $this->redirector->getUrlGenerator();
52
+
53
+
54
+
55
+ if ($this->redirect) {
56
+
57
+ return $url->to($this->redirect);
58
+
59
+ } elseif ($this->redirectRoute) {
60
+
61
+ return $url->route($this->redirectRoute);
62
+
63
+ } elseif ($this->redirectAction) {
64
+
65
+ return $url->action($this->redirectAction);
66
+
67
+ }
68
+
69
+
70
+
71
+ return $url->previous();
72
+
73
+ }
74
+
75
+ ```