@extends('layouts.app') @section('title', 'E-post') @section('content') @php $tenant = auth()->user()->tenant; $folder = request('folder', 'inbox'); $emails = $tenant->emails() ->when($folder === 'inbox', fn($q) => $q->where('direction','inbound')->where('folder','inbox')) ->when($folder === 'sent', fn($q) => $q->where('direction','outbound')) ->when($folder === 'starred', fn($q) => $q->where('is_starred', true)) ->with('customer')->orderByDesc('received_at')->paginate(25); $unread = $tenant->emails()->where('is_read', false)->count(); $selectedId = request('email'); $selected = $selectedId ? $tenant->emails()->with('customer')->find($selectedId) : null; @endphp