Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Enable default retrieval of all fragments in fragments() and fragmentsIf() methods #48894

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,32 @@ public function fragment($fragment)
});
}

/**
* Get all fragments and return as a single string.
*
* @return string
*/
protected function allFragments()
{
$fragments = $this->render(fn() => $this->factory->getFragments());

return collect($fragments)->implode('');
}

/**
* Get the evaluated contents for a given array of fragments.
* If no fragments are provided, return all fragments.
tabuna marked this conversation as resolved.
Show resolved Hide resolved
*
* @param array|null $fragments
*
tabuna marked this conversation as resolved.
Show resolved Hide resolved
* @param array $fragments
* @return string
*/
public function fragments(array $fragments)
public function fragments(array|null $fragments = null)
tabuna marked this conversation as resolved.
Show resolved Hide resolved
{
if ($fragments === null) {
return $this->allFragments();
}

return collect($fragments)->map(fn ($f) => $this->fragment($f))->implode('');
}

Expand All @@ -121,10 +139,10 @@ public function fragmentIf($boolean, $fragment)
* Get the evaluated contents for a given array of fragments if the given condition is true.
*
* @param bool $boolean
* @param array $fragments
* @param array|null $fragments
* @return string
*/
public function fragmentsIf($boolean, array $fragments)
public function fragmentsIf($boolean, array|null $fragments = null)
tabuna marked this conversation as resolved.
Show resolved Hide resolved
{
if (value($boolean)) {
return $this->fragments($fragments);
Expand Down