1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Livewire/DownloadsTable.php

52 lines
1.3 KiB
PHP
Raw Normal View History

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;
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();
if (in_array('resources', $this->status) && ! in_array('client', $this->status)) {
$query = $query->where('documentable_type', '!=', \App\Models\Client::class);
}
if (in_array('client', $this->status) && ! in_array('resources', $this->status)) {
$query = $query->where('documentable_type', \App\Models\Client::class);
}
$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,
]);
}
}