mauricius / laravel-htmx

Laravel helper library for Htmx
MIT License
301 stars 14 forks source link

Added htmx() response macro #3

Closed markovic-nikola closed 1 year ago

markovic-nikola commented 1 year ago

Hi,

I came up with a simple Response macro, I explained in the README file:

response()->htmx(...)

If you just want to pass the simple HTML response using Laravel view, you can also use the htmx() macro response.

Route::get('/', fn () => response()->htmx($viewName, $viewData));

Additionally, this macro can also handle Laravel's built-in validation $errors message bag and old() input session data:

Route::get('/', fn () => response()->htmx($viewName, $viewData, $validator));

This can be useful when submitting forms via HTMX and you want to show validation errors within the same response.