64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
use Livewire\WithoutUrlPagination;
|
|
|
|
use App\Models\Agent\Agent;
|
|
use App\Models\Company\CompanyAdmin;
|
|
use App\Models\Deal\Deal;
|
|
|
|
class ClientsTable extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public $status;
|
|
|
|
public function mount($status = null)
|
|
{
|
|
$this->status = $status;
|
|
}
|
|
|
|
public function getDeals()
|
|
{
|
|
$deals = false;
|
|
$user = auth()->user();
|
|
if ($agent = Agent::where('user_id', $user->id)->first())
|
|
{
|
|
$deals = Deal::where('agent_id', $agent->id);
|
|
}
|
|
elseif ($admin = CompanyAdmin::where('user_id', $user->id)->first())
|
|
{
|
|
$deals = Deal::whereIn('agent_id', function ($query) use ($admin)
|
|
{
|
|
$query->select('id');
|
|
$query->from('agents');
|
|
$query->where('company_id', $admin->company_id);
|
|
});
|
|
}
|
|
return $deals;
|
|
}
|
|
public function render()
|
|
{
|
|
$deals = $this->getDeals();
|
|
if ($this->status && $this->status == 'UNIQUE')
|
|
{
|
|
$deals = $deals->where('status', $this->status)->paginate(8);
|
|
}
|
|
else
|
|
{
|
|
$deals = $deals->paginate(8);
|
|
}
|
|
;
|
|
|
|
return view(
|
|
'livewire.clients-table',
|
|
[
|
|
'deals' => $deals
|
|
]
|
|
);
|
|
}
|
|
}
|