PHP code example of lao9s / livewire-modal-twitter

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

    

lao9s / livewire-modal-twitter example snippets




namespace App\Http\Livewire;

use Lao9s\LivewireModalTwitter\Component\ModalTwitterComponent;

class ShowPost extends ModalTwitterComponent
{
    public function mount()
    {
        // Set images with the method setImages()
        $this->setImages([asset('img/1.jpg')]);
    }
    
    public function render()
    {
        return view('livewire.show-post');
    }
}



namespace App\Http\Livewire;

use Illuminate\Support\Facades\Http;
use Lao9s\LivewireModalTwitter\Component\ModalTwitterComponent;

class ShowPost extends ModalTwitterComponent
{
    public static function hasLoading(): bool
    {
        return true;
    }
    
    public function dispatch(): void
    {
        $request = Http::get('/api/post');
        // Set images with the method setImages()
        $this->setImages($request['images']);
    }
    
    public function render()
    {
        return view('livewire.show-post');
    }
}



namespace App\Http\Livewire;

use Lao9s\LivewireModalTwitter\Component\ModalTwitterComponent;

class ShowPost extends ModalTwitterComponent
{
    public function mount($post_id)
    {  
       // Your logic
    }

    public function render()
    {
        return view('livewire.show-post');
    }
}
shell
php artisan vendor:publish --tag=livewire-modal-twitter:public --force
shell
php artisan vendor:publish --tag=livewire-modal-twitter:views
html
<!-- Outside of any Livewire component -->
<button onclick='Livewire.emit("openModalTwitter", "show-post", {{ json_encode(["post_id" => $post->id]) }})'>Show Post</button>

<!-- Inside existing Livewire component -->
<button wire:click='$emit("openModalTwitter", "show-post", {{ json_encode(["post_id" => $post->id]) }})'>Show Post</button>