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 all 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
24 changes: 18 additions & 6 deletions src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ public function fragment($fragment)
}

/**
* Get the evaluated contents for a given array of fragments.
* Get the evaluated contents for a given array of fragments or return all fragments.
*
* @param array $fragments
* @param array|null $fragments
* @return string
*/
public function fragments(array $fragments)
public function fragments(?array $fragments = null)
{
return collect($fragments)->map(fn ($f) => $this->fragment($f))->implode('');
return is_null($fragments)
? $this->allFragments()
: collect($fragments)->map(fn ($f) => $this->fragment($f))->implode('');
}

/**
Expand All @@ -121,10 +123,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 $fragments = null)
{
if (value($boolean)) {
return $this->fragments($fragments);
Expand All @@ -133,6 +135,16 @@ public function fragmentsIf($boolean, array $fragments)
return $this->render();
}

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

/**
* Get the string contents of the view.
*
Expand Down