2020-08-14 17:29:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use App\Models\Document;
|
|
|
|
use App\Utils\Traits\WithSorting;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Livewire\WithPagination;
|
|
|
|
|
|
|
|
class DownloadsTable extends Component
|
|
|
|
{
|
|
|
|
use WithPagination, WithSorting;
|
|
|
|
|
|
|
|
public $per_page = 10;
|
|
|
|
|
2020-08-17 16:31:49 +02:00
|
|
|
public $status = [
|
|
|
|
'resources',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function statusChange($status)
|
|
|
|
{
|
|
|
|
if (in_array($status, $this->status)) {
|
|
|
|
return $this->status = array_diff($this->status, [$status]);
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($this->status, $status);
|
|
|
|
}
|
|
|
|
|
2020-08-14 17:29:26 +02:00
|
|
|
public function render()
|
|
|
|
{
|
2020-08-19 18:06:26 +02:00
|
|
|
// $query = auth('contact')->user()->client->documents();
|
|
|
|
$query = Document::query();
|
2020-08-17 16:31:49 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (in_array('resources', $this->status) && ! in_array('client', $this->status)) {
|
|
|
|
$query = $query->where('documentable_type', '!=', \App\Models\Client::class);
|
2020-08-17 16:31:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (in_array('client', $this->status) && ! in_array('resources', $this->status)) {
|
|
|
|
$query = $query->where('documentable_type', \App\Models\Client::class);
|
2020-08-17 16:31:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = $query
|
2020-08-19 18:06:26 +02:00
|
|
|
// ->where('is_public', true)
|
2020-08-14 17:29:26 +02:00
|
|
|
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
|
|
|
->paginate($this->per_page);
|
|
|
|
|
|
|
|
return render('components.livewire.downloads-table', [
|
|
|
|
'downloads' => $query,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|