2024-07-05 10:35:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Club;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2026-03-06 13:00:14 +01:00
|
|
|
use App\Http\Requests\Club\Notifications\DeleteNotificationsRequest;
|
|
|
|
|
use App\Models\Notification;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2026-03-06 13:00:14 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-07-18 12:13:35 +02:00
|
|
|
use Illuminate\Support\Facades\View as FacadesView;
|
2024-07-05 10:35:26 +02:00
|
|
|
|
|
|
|
|
class NotificationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Show index page
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function index(): View
|
2024-07-05 10:35:26 +02:00
|
|
|
{
|
2024-07-29 11:32:50 +02:00
|
|
|
/** @var \App\Models\Customer $customerModel */
|
|
|
|
|
$customerModel = auth('club')->user();
|
2026-03-06 13:00:14 +01:00
|
|
|
$notificationModels = $customerModel->notifications()
|
2026-09-25 16:25:31 +02:00
|
|
|
->whereNotIn('id', $customerModel->readNotifications()->pluck('notification_id'))
|
|
|
|
|
->orderBy('created_at', 'DESC')
|
|
|
|
|
->paginate(10);
|
|
|
|
|
|
2024-07-29 11:32:50 +02:00
|
|
|
return view('club.pages.notifications.index', compact('notificationModels'));
|
2024-07-05 10:35:26 +02:00
|
|
|
}
|
2024-07-18 12:13:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get notifications count
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function notificationsCount(): JsonResponse
|
2024-07-18 12:13:35 +02:00
|
|
|
{
|
|
|
|
|
return response()->json(FacadesView::shared('notifications_count', 0));
|
|
|
|
|
}
|
2026-03-06 13:00:14 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete notification from list
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function destroy(Notification $notification): JsonResponse
|
2026-03-06 13:00:14 +01:00
|
|
|
{
|
|
|
|
|
/** @var \App\Models\Customer $customer */
|
|
|
|
|
$customer = Auth::guard('club')->user();
|
|
|
|
|
|
|
|
|
|
$customer->readNotifications()->syncWithoutDetaching($notification->id);
|
|
|
|
|
session()->flash('success', __('Notification supprimée.'));
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2026-03-06 13:00:14 +01:00
|
|
|
return response()->json(['success' => true]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete notification from list
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function destroyMultiple(DeleteNotificationsRequest $request): JsonResponse
|
2026-03-06 13:00:14 +01:00
|
|
|
{
|
|
|
|
|
/** @var \App\Models\Customer $customer */
|
|
|
|
|
$customer = Auth::guard('club')->user();
|
|
|
|
|
|
|
|
|
|
$customer->readNotifications()->syncWithoutDetaching($request->validated('ids'));
|
|
|
|
|
|
|
|
|
|
$count = count($request->validated(('ids')));
|
|
|
|
|
|
|
|
|
|
session()->flash('success', trans_choice(
|
2026-05-06 17:11:13 +02:00
|
|
|
'{1} Notification supprimée.|[2,*] :count notifications supprimées.',
|
|
|
|
|
$count,
|
|
|
|
|
['count' => $count]
|
2026-03-06 13:00:14 +01:00
|
|
|
));
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2026-03-06 13:00:14 +01:00
|
|
|
return response()->json(['success' => true]);
|
|
|
|
|
}
|
2026-05-06 17:11:13 +02:00
|
|
|
}
|