PHP code example of epessine / vessel

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

    

epessine / vessel example snippets


use Vessel\BaseVessel;

class FilterVessel extends BaseVessel
{
    public string $selectedUserType = 'admin';
}

use Vessel\BaseVessel;

class FilterVessel extends BaseVessel
{
    public string $selectedUserType;

    public function init(): void
    {
        $this->selectedUserType = str('admin')->toString();
    }
}

use Livewire\Component;
use Vessel\Attributes\Vessel;

/**
 * @property-read FilterVessel globalFilters
 */
class Filter extends Component
{
    #[Vessel]
    public function globalFilters(): string
    {
        return FilterVessel::class; // vessel class declared above
    }

    public function selectUserFilter(string $type): void
    {
        // here we change the vessel property value
        $this->globalFilters->selectedUserType = $type;
    }

    // ...
}

use Livewire\Component;
use Vessel\Attributes\Vessel;

/**
 * @property-read FilterVessel globalFilters
 */
class UserList extends Component
{
    #[Vessel]
    public function globalFilters(): string
    {
        return FilterVessel::class; // vessel class declared above
    }

    #[Computed]
    public function users(): array
    {
        // here we get the updated vessel property value
        User::query()
            ->where('type', $this->globalFilters->selectedUserType)
            ->get()
            ->all();
    }

    // ...
}

use Livewire\Component;
use Vessel\Attributes\Vessel;

/**
 * @property-read FilterVessel globalFilters
 */
class UserList extends Component
{
    public array $users;

    #[Vessel]
    public function globalFilters(): string
    {
        return FilterVessel::class; // vessel class declared above
    }

    public function updatedGlobalFiltersSelectedUserType(string $value): void
    {
        // here we get the updated vessel property value
        $this->users = User::query()->where('type', $value)->get()->all();
    }

    // ...
}