Skip to content

Commit ecf7170

Browse files
committed
Refactoring Efficiently\JqueryLaravel\ControllerAdditions::render() and makeView()
Add makeLayout() method
1 parent 9850b0b commit ecf7170

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Efficiently/JqueryLaravel/ControllerAdditions.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trait ControllerAdditions
2121
public function render($view, $data = [], $options = null)
2222
{
2323
list($view, $options) = $this->makeView($view, $data, $options);
24+
$view = $this->makeLayout($view, $options);
2425

2526
return $this->makeResponse($view, $options);
2627
}
@@ -29,7 +30,7 @@ public function render($view, $data = [], $options = null)
2930
* @param \Illuminate\View\View|string|array $view [description]
3031
* @param array $data
3132
* @param mixed $options
32-
* @return array [\Illuminate\View\View $view, array $options]
33+
* @return array [\Illuminate\View\View|string $view, array $options]
3334
*/
3435
protected function makeView($view, $data = [], $options = null)
3536
{
@@ -77,19 +78,33 @@ protected function makeView($view, $data = [], $options = null)
7778
// Transform the $view string path to a View object
7879
$view = view($view, $data);
7980
}
81+
$options['layout'] = $layout;
82+
$options['format'] = $format;
8083

84+
return [$view, $options];
85+
}
86+
87+
/**
88+
* @param \Illuminate\View\View|string $view
89+
* @param array $options
90+
* @return \Illuminate\View\View|string
91+
*/
92+
protected function makeLayout($view, $options = [])
93+
{
94+
$layout = array_pull($options, 'layout');
8195
$this->setupLayout($layout);
82-
if ($this->layout && $this->layout->getName() !== $view->getName()) {
96+
if ($this->layout &&
97+
(is_string($view) || $this->layout->getName() !== $view->getName())
98+
) {
8399
$this->layout->with('content', $view);
84100
$view = $this->layout;
85101
}
86-
$options['format'] = $format;
87102

88-
return [$view, $options];
103+
return $view;
89104
}
90105

91106
/**
92-
* @param \Illuminate\View\View $view
107+
* @param \Illuminate\View\View|string $view
93108
* @param array $options
94109
* @return \Illuminate\Http\Response
95110
*/

0 commit comments

Comments
 (0)