@@ -16,13 +16,24 @@ trait ControllerAdditions
16
16
* If $options is null, the master layout is set with the value of the Controller::$layout property.
17
17
* If $options is a boolean, if it's `false`, no layout is applied on the view.
18
18
* If $options is an array, default values are: ['status' => 200, 'headers' => []]
19
- *
20
19
* @return \Illuminate\Http\Response
21
20
*/
22
21
public function render ($ view , $ data = [], $ options = null )
22
+ {
23
+ list ($ view , $ options ) = $ this ->makeView ($ view , $ data , $ options );
24
+
25
+ return $ this ->makeResponse ($ view , $ options );
26
+ }
27
+
28
+ /**
29
+ * @param \Illuminate\View\View|string|array $view [description]
30
+ * @param array $data
31
+ * @param mixed $options
32
+ * @return array [\Illuminate\View\View $view, array $options]
33
+ */
34
+ protected function makeView ($ view , $ data = [], $ options = null )
23
35
{
24
36
$ layout = null ;
25
- $ defaultOptions = ['status ' => 200 , 'headers ' => []];
26
37
if (is_string ($ options )) {
27
38
// To support legacy behaviour
28
39
$ layout = $ options ;
@@ -39,7 +50,6 @@ public function render($view, $data = [], $options = null)
39
50
}
40
51
$ options = [];
41
52
}
42
- $ options = array_merge ($ defaultOptions , $ options );
43
53
44
54
$ format = null ; // if `null`, it uses the 'html' format by default
45
55
if (is_array ($ view ) && count ($ view ) === 1 ) {
@@ -67,18 +77,32 @@ public function render($view, $data = [], $options = null)
67
77
// Transform the $view string path to a View object
68
78
$ view = view ($ view , $ data );
69
79
}
70
- $ render = $ view ;
71
80
72
81
$ this ->setupLayout ($ layout );
73
82
if ($ this ->layout && $ this ->layout ->getName () !== $ view ->getName ()) {
74
- $ this ->layout ->with ('content ' , $ render );
75
- $ render = $ this ->layout ;
83
+ $ this ->layout ->with ('content ' , $ view );
84
+ $ view = $ this ->layout ;
76
85
}
86
+ $ options ['format ' ] = $ format ;
87
+
88
+ return [$ view , $ options ];
89
+ }
90
+
91
+ /**
92
+ * @param \Illuminate\View\View $view
93
+ * @param array $options
94
+ * @return \Illuminate\Http\Response
95
+ */
96
+ protected function makeResponse ($ view , $ options = [])
97
+ {
98
+ $ format = array_pull ($ options , 'format ' );
99
+ $ defaultOptions = ['status ' => 200 , 'headers ' => []];
100
+ $ options = array_merge ($ defaultOptions , $ options );
77
101
78
102
if (response ()->hasMacro ('makeWithTurbolinks ' )) {
79
- $ response = response ()->makeWithTurbolinks ($ render , $ options );
103
+ $ response = response ()->makeWithTurbolinks ($ view , $ options );
80
104
} else {
81
- $ response = response ($ render , $ options ['status ' ], $ options ['headers ' ]);
105
+ $ response = response ($ view , $ options ['status ' ], $ options ['headers ' ]);
82
106
}
83
107
if ($ format ) {
84
108
$ response ->header ('Content-Type ' , Request::getMimeType ($ format ));
@@ -90,7 +114,6 @@ public function render($view, $data = [], $options = null)
90
114
/**
91
115
* @param string $path URL
92
116
* @param array $options Default to: ['status' => 302, 'headers' => [], 'secure' => null]
93
- *
94
117
* @return \Illuminate\Http\RedirectResponse
95
118
*/
96
119
public function redirectTo ($ path , $ options = [])
@@ -106,6 +129,7 @@ public function redirectTo($path, $options = [])
106
129
107
130
/**
108
131
* Setup the layout used by the controller.
132
+ *
109
133
* @param string|bool|\Illuminate\View\View $layout Custom layout
110
134
* @return void
111
135
*/
0 commit comments