@@ -16,13 +16,24 @@ trait ControllerAdditions
1616 * If $options is null, the master layout is set with the value of the Controller::$layout property.
1717 * If $options is a boolean, if it's `false`, no layout is applied on the view.
1818 * If $options is an array, default values are: ['status' => 200, 'headers' => []]
19- *
2019 * @return \Illuminate\Http\Response
2120 */
2221 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 )
2335 {
2436 $ layout = null ;
25- $ defaultOptions = ['status ' => 200 , 'headers ' => []];
2637 if (is_string ($ options )) {
2738 // To support legacy behaviour
2839 $ layout = $ options ;
@@ -39,7 +50,6 @@ public function render($view, $data = [], $options = null)
3950 }
4051 $ options = [];
4152 }
42- $ options = array_merge ($ defaultOptions , $ options );
4353
4454 $ format = null ; // if `null`, it uses the 'html' format by default
4555 if (is_array ($ view ) && count ($ view ) === 1 ) {
@@ -67,18 +77,32 @@ public function render($view, $data = [], $options = null)
6777 // Transform the $view string path to a View object
6878 $ view = view ($ view , $ data );
6979 }
70- $ render = $ view ;
7180
7281 $ this ->setupLayout ($ layout );
7382 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 ;
7685 }
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 );
77101
78102 if (response ()->hasMacro ('makeWithTurbolinks ' )) {
79- $ response = response ()->makeWithTurbolinks ($ render , $ options );
103+ $ response = response ()->makeWithTurbolinks ($ view , $ options );
80104 } else {
81- $ response = response ($ render , $ options ['status ' ], $ options ['headers ' ]);
105+ $ response = response ($ view , $ options ['status ' ], $ options ['headers ' ]);
82106 }
83107 if ($ format ) {
84108 $ response ->header ('Content-Type ' , Request::getMimeType ($ format ));
@@ -90,7 +114,6 @@ public function render($view, $data = [], $options = null)
90114 /**
91115 * @param string $path URL
92116 * @param array $options Default to: ['status' => 302, 'headers' => [], 'secure' => null]
93- *
94117 * @return \Illuminate\Http\RedirectResponse
95118 */
96119 public function redirectTo ($ path , $ options = [])
@@ -106,6 +129,7 @@ public function redirectTo($path, $options = [])
106129
107130 /**
108131 * Setup the layout used by the controller.
132+ *
109133 * @param string|bool|\Illuminate\View\View $layout Custom layout
110134 * @return void
111135 */
0 commit comments