Download the PHP package mauricius/laravel-htmx without Composer
On this page you can find all versions of the php package mauricius/laravel-htmx. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mauricius/laravel-htmx
More information about mauricius/laravel-htmx
Files in mauricius/laravel-htmx
Package laravel-htmx
Short Description Laravel helper library for Htmx
License MIT
Homepage https://github.com/mauricius/laravel-htmx
Informations about the package laravel-htmx
laravel-htmx
Laravel integration for htmx.
Supported Laravel Versions >= v8.80.0.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
To install htmx please browse their documentation
Usage
Request
You can resolve an instance of the HtmxRequest
from the container which provides shortcuts for reading the htmx-specific request headers.
Response
HtmxResponseClientRedirect
htmx can trigger a client side redirect when it receives a response with the HX-Redirect
header. The HtmxResponseClientRedirect
makes it easy to trigger such redirects.
HtmxResponseClientRefresh
htmx will trigger a page reload when it receives a response with the HX-Refresh
header. HtmxResponseClientRefresh
is a custom response class that allows you to send such a response. It takes no arguments, since htmx ignores any content.
HtmxResponseStopPolling
When using a polling trigger, htmx will stop polling when it encounters a response with the special HTTP status code 286. HtmxResponseStopPolling
is a custom response class with that status code.
For all the remaining available headers you can use the HtmxResponse
class.
Additionally, you can trigger client-side events using the addTrigger
methods.
If you want to pass details along with the event you can use the second argument to send a body. It supports strings or arrays.
You can call those methods multiple times if you want to trigger multiple events.
Render Blade Fragments
This library also provides a basic Blade extension to render template fragments.
The library provides two new Blade directives: @fragment
and @endfragment
. You can use these directives to specify a block of content within a template and render just that bit of content. For instance:
With this fragment defined in our template, we can now render either the entire template:
Or we can render only the archive-ui
fragment of the template by using the renderFragment
macro defined in the \Illuminate\View\View
class:
OOB Swap support
htmx supports updating multiple targets by returning multiple partial responses with hx-swap-oop
. With this library you can return multiple fragments by using the HtmxResponse
as a return type.
For instance, let's say that we want to mark a todo as completed using a PATCH request to /todos/{id}
. With the same request, we also want to update in the footer how many todos are left:
We can use the HtmxResponse
to return multiple fragments:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- mauricius
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-htmx with dependencies
php Version ^8.1
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0