Skip to content

Commit

Permalink
[10.x] Enable default retrieval of all fragments in fragments() and…
Browse files Browse the repository at this point in the history
… `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]>
  • Loading branch information
3 people authored Nov 3, 2023
1 parent 0ca0d32 commit 9c73544
Showing 1 changed file with 18 additions and 6 deletions.
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

0 comments on commit 9c73544

Please sign in to comment.