@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
@foreach([['inbox','Inkorg','M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2zM22 6l-10 7L2 6',$unread],['sent','Skickat','M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z',0],['starred','Stjärnor','M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z',0]] as [$fid,$flbl,$fpath,$fcnt])
{{ $flbl }}
@if($fcnt > 0){{ $fcnt }}@endif
@endforeach
@csrf
{{ ucfirst($folder) }} {{ $emails->total() }} st
@forelse($emails as $email)
{{ strtoupper(substr($email->from_name ?? $email->from_email, 0, 1)) }}
{{ $email->from_name ?? $email->from_email }} {{ $email->received_at->diffForHumans() }}
{{ $email->subject }}
{{ Str::limit(strip_tags($email->body_text ?? ''), 60) }}
@if(!$email->is_read)
@endif @if($email->customer){{ Str::limit($email->customer->name,18) }}@endif {{ $email->status==='open'?'Öppen':($email->status==='replied'?'Besvarad':'Arkiverad') }}
@empty
Inga meddelanden
Konfigurera e-postkonto →
@endforelse
@if($selected)
{{ $selected->subject }}
Fra: {{ $selected->from_name ?? $selected->from_email }}
{{ $selected->received_at->format('d M Y, H:i') }}
@if($selected->customer)Kund: {{ $selected->customer->name }} →@endif
@if($selected->body_html)
{!! $selected->body_html !!}
@else
{{ $selected->body_text }}
@endif
@endif
@push('scripts') @endpush @endsection