PHP code example of xlited / lamx

1. Go to this page and download the library: Download xlited/lamx 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/ */

    

xlited / lamx example snippets


namespace App\View\Components;

use Xlited\Lamx\Components\HtmxComponent;

class Todo extends HtmxComponent
{
    public function __construct(public int $id, public string $title, public bool $done = false)
    {
    }

    // Actions are public methods. They run against the component as it was rendered.
    public function toggle(): void
    {
        $this->done = ! $this->done;

        Todo::where('id', $this->id)->update(['done' => $this->done]);
    }
}

class TodoForm extends HtmxComponent
{
    protected function rules(): array
    {
        return ['title' => 'title']);

        return [static::make(), Todo::make($todo)];
    }
}

Route::get('/', Todos::class);
blade
{{-- resources/views/components/todo.blade.php --}}
<div id="todo-{{ $this->id }}" @class(['line-through' => $this->done])>
    <input type="checkbox" @checked($this->done)
           hx-post="{{ $this->action('toggle') }}" hx-target="closest div" hx-swap="outerHTML">
    {{ $this->title }}
</div>