laravel-livewire-tables icon indicating copy to clipboard operation
laravel-livewire-tables copied to clipboard

How to pass variable?

Open lovecoding-git opened this issue 5 years ago • 2 comments

I want to pass variable to livewire component. @livewire('livewire-component', ['type'=>'A']) public function mount($type) { $this->setTableProperties(); $this->type = $type; } It displayed error. Declaration of App\Http\Livewire\LivewireComponent::mount($type) should be compatible with Kdion4891\LaravelLivewireTables\TableComponent::mount() (View: ~\resources\views\app\tabl.blade.php)

Thanks

lovecoding-git avatar May 12 '20 09:05 lovecoding-git

<?php

namespace Kdion4891\LaravelLivewireTables;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Kdion4891\LaravelLivewireTables\Traits\ThanksYajra;
use Livewire\Component;
use Livewire\WithPagination;

class TableComponent extends Component
{
    use WithPagination, ThanksYajra;

    public $table_class;
    public $thead_class;
    public $header_view;
    public $footer_view;
    public $search;
    public $checkbox;
    public $checkbox_side;
    public $checkbox_attribute = 'id';
    public $checkbox_all = false;
    public $checkbox_values = [];
    public $sort_attribute = 'id';
    public $sort_direction = 'desc';
    public $per_page;

    public function mount($type=null)
    {
        $this->setTableProperties();
    }

I added $type field and it worked well. :)

lovecoding-git avatar May 12 '20 10:05 lovecoding-git

You don't need to touch the original class. You can override the mount method with optional parameters (id is obligatory) Example:


public function mount($id=null,$institucion=false){
        if ($institucion!==false )  
        $this->filterinstitucion = $institucion->id; 
        $this->setTableProperties();

    }

horaciod avatar Jun 21 '20 22:06 horaciod