mirror of https://github.com/Lukibeg/OmniBoard.git
37 lines
968 B
PHP
37 lines
968 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Inertia\Inertia;
|
|
use App\Models\User;
|
|
use App\Models\Queue;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Carbon\Carbon;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$user = Auth::user();
|
|
|
|
// 1. Começa a query base (apenas filas do Tenant do usuário)
|
|
$query = Queue::where('tenant_id', $user->tenant_id)
|
|
->with(['dailyMetrics', 'waitingList']); // Carrega relacionamentos
|
|
|
|
// 2. APLICAR O FILTRO DE SETOR
|
|
// Se o usuário tiver algo escrito em 'allowed_sector', filtramos.
|
|
// Se for null, ele pula esse if e traz tudo.
|
|
if (!empty($user->allowed_sector)) {
|
|
$query->where('sector', $user->allowed_sector);
|
|
}
|
|
|
|
// 3. Executa a query
|
|
$queues = $query->get();
|
|
|
|
// 4. Entrega para o Vue
|
|
return Inertia::render('Dashboard', [
|
|
'queues' => $queues
|
|
]);
|
|
}
|
|
}
|