1. Go to this page and download the library: Download imsus/laravel-htmx library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
imsus / laravel-htmx example snippets
use Illuminate\Http\Request;
Route::get('/items', function (Request $request) {
return view('items', ['items' => Item::all()])
->fragmentIf($request->isPartial(), 'rows');
});
$request->isPartial(); // In controllers.
htmx()->isPartial(); // Anywhere via the helper.
Htmx::isPartial(); // Via the facade in services and jobs.
$request->file('avatar'); // Just like any other upload.
// Skip the swap entirely while the poll tag is current.
return htmx()->poll(view('feed', ['items' => $items]), 'news', $current);
// Read the answer from a pre-request prompt.
$reason = $request->prompt();
// Preloads may never be seen — keep them cheap, never write.
if ($request->isPreloaded()) {
// Serve something light.
}
// Stream HTML updates over one response (hx-sse).
return htmx()->eventStream([
'<p>warming up</p>',
['data' => '<p>done</p>', 'id' => 'e42'],
]);
// Download a file on the side while the response swaps normally.
return response('<span>Started…</span>')->download('/files/report.pdf');