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

Adds fragments() and fragmentsIf() method #45669

Merged
merged 3 commits into from
Jan 16, 2023
Merged

Adds fragments() and fragmentsIf() method #45669

merged 3 commits into from
Jan 16, 2023

Conversation

arkoe
Copy link
Contributor

@arkoe arkoe commented Jan 16, 2023

Adds fragments() and fragmentsIf() function.
With htmx (and probably similar libraries) you can swap out of bounds, allowing you to update multiple sections of a page, requiring multiple fragments. The current way to do this is by concatenating two (or more) fragments:

return view('welcome')->fragment('fragment1') . view('welcome')->fragment('fragment2');

With fragments() this is simplified to:

return view('welcome')->fragments(['fragment1', 'fragment2']);

or

return view('welcome')->fragments('fragment1', 'fragment2');

Also a fragmentsIf() to conditionally return these fragments have been added in this PR. This is basically an expansion on PR #45656, allowing you to conditionally return multiple fragments:

return view('welcome')->fragmentsIf(request()->hasHeader('HX-Request'), ['fragment1', 'fragment2']);

or

return view('welcome')->fragmentsIf(request()->hasHeader('HX-Request'), 'fragment1', 'fragment2');

@taylorotwell taylorotwell merged commit 31fa534 into laravel:9.x Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants