@extends('setting.nav') @section('title', 'Mail Routing') @section('content')

Automatic Email Assignment

Which team owns which kind of mail. The classifier already decides what each mail is — a pricing enquiry, a support request, an invoice — and these rows turn that into an owner, so a sales enquiry reaches the sales team without anybody sorting the inbox. Nothing extra is asked of the AI: an org chart is not something it can read out of an email.

@if (session('success')) @endif @if (session('error')) @endif @php $isAdmin = auth()->check() && auth()->user()->auth_id == 0; $mapped = $categories->filter(fn($category) => (int) ($category->assign_department_id ?? 0) > 0)->count(); @endphp @if ($departments->isEmpty()) {{-- Nothing to route TO. Said first and plainly, because every dropdown on this screen would otherwise be empty with no explanation. --}}
No teams yet. Routing needs somewhere to route to. Create your teams on the Departments screen, then give each one a head and its members on Assign Department — the head is the person mail is handed to by name.
@elseif ($mapped === 0)
Nothing is routed yet, so nothing is being assigned. That is the starting state: a mapping cannot be guessed, and quietly sending a customer's complaint to whichever team sorted first is worse than assigning nothing. Point each category at a team below.
@endif @if ($usingDefaults) {{-- The vocabulary has never been saved, so there are no rows to hang a mapping on. Saving creates them — worth saying before the submit rather than after. --}}
Running on the built-in categories. These eleven are what the classifier is already using. Saving a mapping stores them as your own categories first, so they can be reworded and reordered afterwards on the Categories screen.
@endif
@csrf
Routing rules
{{ $mapped }} of {{ $categories->count() }} categories routed
@foreach ($categories as $category) @php $code = strtolower((string) $category->code); $currentId = (int) ($category->assign_department_id ?? 0); // Aliases folded in, so a category counts the mail // classified under the older words it claims — the // same rule the mail list's pill follows. $volume = $volumes[$code] ?? 0; foreach ($category->aliasList() as $alias) { $volume += $volumes[$alias] ?? 0; } @endphp @endforeach
When a mail is classified as… …assign it to Named owner Mail so far
{{ $category->name }} @if ($category->description)
{{ \Illuminate\Support\Str::limit($category->description, 110) }}
@endif
@if ($currentId > 0 && !empty($heads[$currentId])) {{ $heads[$currentId] }} @elseif ($currentId > 0) {{-- A team with no head still receives mail; it just belongs to the queue rather than to a desk. Worth flagging here, where it can be fixed. --}} no head @else — @endif {{ number_format($volume) }}
@if ($isAdmin && $departments->isNotEmpty()) @elseif (!$isAdmin) @endif
Where mail stands
Has an owner {{ number_format($assignedTotal) }}
Classified, nobody owns it {{ number_format($unassigned) }}
@if ($unassigned > 0)

Mail already in the inbox is not re-routed when you change these rules — somebody may be part-way through replying to it. To give the unowned mail above its team, run:

php artisan mail:assign-existing --dry-run

It reports what it would do; drop --dry-run to write. Mail somebody has assigned by hand is never touched.

@endif
How a mail finds its owner
  1. The classifier decides what the mail is — one of the categories on the left. This already happens for every mail.
  2. The rule above turns that category into a team.
  3. The team's head becomes the named owner. A team with no head keeps the mail as a queue.
  4. Anyone can reassign a single mail from the mail itself, and a hand-assigned mail is never reassigned automatically.

The Assigned chip on the inbox toolbar opens what is yours — across every mailbox in the account, since mail addressed to the company does not arrive in your own.

@endsection