I have this livewire component which filters a table based on the two dropdown buttons. one is called Instance and the other Job. I would like to find a way to filter both buttons.
in this way or I pass it to render updatejob or updateinstance. So only one of the two buttons works. is there any way to make them both work?
in the sense that if I use a public variable to which I pass the query results through the two methods it does not allow me to do the pagination since I would operate its public variable that allows collections
namespace App\Http\Livewire;
use Livewire\WithPagination;
use App\Models\Task;
use Livewire\Component;
class TableTodo extends Component
{
use WithPagination;
public $instance;
public $job;
public $work;
// public $tasks;
public $elements;
public function updatinginstance()
{
$this->resetPage();
}
public function mount()
{
$this->instance='';
$this->job='';
// $this->tasks=[];
$this->elements=[];
$this->work=[];
}
public function updatedelements()
{
$in = Task::find($this->instance);
if(!empty($in))
{
$tasks= Task::whereIn('process_status', ['B','C'];
}
else
{
$tasks= Task::whereIn('process_status', ['A'])
->orderByRaw('FIELD(process_status, "new", "processing")asc')
->orderBy('created_at', 'asc')
->paginate(50)
;
}
return $tasks;
}
public function updatedwork()
{
$in_job = Task::find($this->job);
if(!empty($in_job))
{
$tasks = Task::whereIn('process_status', ['A'])
->where('job', 'like', $in_job->job)
->orderBy('created_at', 'asc')
->paginate(50);
}
else
{
$tasks = Task::whereIn('process_status', ['A'])
->orderBy('created_at', 'asc')
->paginate(50);
}
return $tasks;
}
public function render()
{
$this->elements = Task::whereIn('process_status', ['A'])->orderBy('created_at', 'asc')->get();
$this->work = Task::whereIn('process_status', ['A'])->orderBy('created_at', 'asc')->get();
$tasks = $this->updatedjob();
$tasks = $this->updatedinstance();
return view('livewire.table-todo',['tasks' => $tasks]);
}
}