PHP code example of marcorieser / statamic-livewire

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

    

marcorieser / statamic-livewire example snippets


namespace App\Http\Livewire;

use Livewire\Component;

class Counter extends Component
{
    public function render()
    {
        return view('livewire.counter');
    }
}

'replacers' => [
    \MarcoRieser\Livewire\Replacers\AssetsReplacer::class,
],

#[Computed]
public function entries() {
    return Entry::all();
}

use Livewire\Component;
use MarcoRieser\Livewire\Attributes\Cascade;

#[Cascade]
class ShowArticle extends Component
{
    ...
}

#[Cascade([
    'title',
    'seo_title' => 'Fallback title',
])]
class ShowArticle extends Component {}

use MarcoRieser\Livewire\WithPagination;

class ShowArticles extends Component
{
    use WithPagination;

    protected function entries()
    {
        $entries = Entry::query()
            ->where('collection', 'articles')
            ->paginate(3);

        return $this->withPagination('entries', $entries);
    }

    public function render()
    {
        return view('livewire.blog-entries', $this->entries());
    }
}

use Statamic\Entries\Entry;

class Foo extends Component
{
    public Entry $entries;
}
js
if (window.livewireScriptConfig?.csrf === 'STATAMIC_CSRF_TOKEN') {
    document.addEventListener('statamic:csrf.replaced', () => Livewire.start());
} else {
    Livewire.start();
}