Skip to content

Commit 9c73544

Browse files
tabunadriesvintstaylorotwell
authored
[10.x] Enable default retrieval of all fragments in fragments() and fragmentsIf() methods (#48894)
* Enable default retrieval of all fragments in `fragments()` and `fragmentsIf()` methods * Fixed docblock * Update src/Illuminate/View/View.php Co-authored-by: Dries Vints <[email protected]> * Update src/Illuminate/View/View.php Co-authored-by: Dries Vints <[email protected]> * Update src/Illuminate/View/View.php Co-authored-by: Dries Vints <[email protected]> * Update src/Illuminate/View/View.php Co-authored-by: Dries Vints <[email protected]> * formatting --------- Co-authored-by: Dries Vints <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0ca0d32 commit 9c73544

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Illuminate/View/View.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ public function fragment($fragment)
9191
}
9292

9393
/**
94-
* Get the evaluated contents for a given array of fragments.
94+
* Get the evaluated contents for a given array of fragments or return all fragments.
9595
*
96-
* @param array $fragments
96+
* @param array|null $fragments
9797
* @return string
9898
*/
99-
public function fragments(array $fragments)
99+
public function fragments(?array $fragments = null)
100100
{
101-
return collect($fragments)->map(fn ($f) => $this->fragment($f))->implode('');
101+
return is_null($fragments)
102+
? $this->allFragments()
103+
: collect($fragments)->map(fn ($f) => $this->fragment($f))->implode('');
102104
}
103105

104106
/**
@@ -121,10 +123,10 @@ public function fragmentIf($boolean, $fragment)
121123
* Get the evaluated contents for a given array of fragments if the given condition is true.
122124
*
123125
* @param bool $boolean
124-
* @param array $fragments
126+
* @param array|null $fragments
125127
* @return string
126128
*/
127-
public function fragmentsIf($boolean, array $fragments)
129+
public function fragmentsIf($boolean, ?array $fragments = null)
128130
{
129131
if (value($boolean)) {
130132
return $this->fragments($fragments);
@@ -133,6 +135,16 @@ public function fragmentsIf($boolean, array $fragments)
133135
return $this->render();
134136
}
135137

138+
/**
139+
* Get all fragments as a single string.
140+
*
141+
* @return string
142+
*/
143+
protected function allFragments()
144+
{
145+
return collect($this->render(fn() => $this->factory->getFragments()))->implode('');
146+
}
147+
136148
/**
137149
* Get the string contents of the view.
138150
*

0 commit comments

Comments
 (0)