fix notif

This commit is contained in:
2026-07-24 16:49:42 +03:30
parent eacf5181a9
commit 107cf5b291
10 changed files with 105 additions and 11 deletions
@@ -5,13 +5,14 @@ namespace App\Http\Controllers\Admin;
use App\DB\Te\TableEngine;
use App\Http\Controllers\Controller;
use App\Models\AppNotification;
use App\Models\AppNotificationRead;
use Illuminate\Http\Request;
class AppNotificationController extends Controller
{
public function table(Request $request)
{
$query = AppNotification::query();
$query = AppNotification::query()->withCount('reads');
TableEngine::create($query, $request->all())
->initSearch(['title', 'body', 'severity'])
@@ -62,6 +63,36 @@ class AppNotificationController extends Controller
return response()->json(true);
}
/** لیست مشتریانی که این اعلان را سین کرده‌اند */
public function readers(int $id)
{
AppNotification::findOrFail($id);
$rows = AppNotificationRead::query()
->where('notification_id', $id)
->with(['customer:id,name,fname,lname,mobile'])
->orderByDesc('read_at')
->orderByDesc('id')
->get();
$readers = $rows->map(function (AppNotificationRead $read) {
$customer = $read->customer;
$name = trim((string) ($customer?->name ?: trim(($customer?->fname ?? '') . ' ' . ($customer?->lname ?? ''))));
return [
'customer_id' => $read->customer_id,
'name' => $name !== '' ? $name : '—',
'mobile' => $customer?->mobile,
'read_at' => $read->read_at,
];
})->values();
return response()->json([
'reads_count' => $readers->count(),
'readers' => $readers,
]);
}
private function validatedPayload(Request $request, bool $partial = false): array
{
$rules = [