Sistema de controles da União de Ciclistas do Brasil
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

69 lines
1.8 KiB

<?php
namespace App\Http\Livewire\Collaborators\Associates;
use App\Associate;
use Livewire\Component;
use Livewire\WithPagination;
class Index extends Component
{
use WithPagination;
/**
* The parameters that should sync with the URL query string
*
* @var array
*/
protected $updatesQueryString = [
'search' => ['except' => ''],
'associate_category_id' => [],
'gender' => [],
];
/** @var string */
public $orderColumn = 'created_at';
/** @var string */
public $orderDirection = 'DESC';
/** @var int */
public $perPage = 10;
/** @var string */
public $search;
/** @var int */
public $associate_category_id;
/** @var string */
public $gender;
public function mount()
{
$this->search = request()->query('search', $this->search);
$this->associate_category_id = request()->query('associate_category_id', $this->associate_category_id);
$this->gender = request()->query('gender', $this->gender);
}
public function updatingSearch()
{
$this->resetPage();
}
public function render()
{
$associates = Associate::with('category')
->where('name', 'LIKE', '%' . $this->search . '%')
->orderBy($this->orderColumn, $this->orderDirection)
->when($this->associate_category_id, function ($query, $associate_category_id) {
return $query->where('associate_category_id', $associate_category_id);
})
->when($this->gender, function ($query, $gender) {
return $query->where('profile->gender', $gender);
})
->paginate($this->perPage);
return view('livewire.collaborators.associates.index', compact('associates'));
}
}