����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/builderbox/././././www/common/Notifications/ |
Upload File : |
<?php
namespace Common\Notifications;
use Auth;
use Carbon\Carbon;
use Common\Core\BaseController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Notifications\DatabaseNotification;
class NotificationController extends BaseController
{
/**
* @var DatabaseNotification
*/
private $notification;
/**
* @var Request
*/
private $request;
/**
* @param DatabaseNotification $notification
* @param Request $request
*/
public function __construct(DatabaseNotification $notification, Request $request)
{
$this->middleware('auth');
$this->notification = $notification;
$this->request = $request;
}
/**
* @return JsonResponse
*/
public function index()
{
$pagination = Auth::user()->notifications()->paginate($this->request->get('perPage', 10));
$pagination->transform(function(DatabaseNotification $notification) {
$notification->relative_created_at = $notification->created_at->diffForHumans();
if ($notification->created_at->isCurrentDay()) {
$notification->time_period = 'today';
} else if ($notification->created_at->isYesterday()) {
$notification->time_period = 'yesterday';
} else if ($notification->created_at->isBetween(Carbon::now()->subDay(), Carbon::now()->subDays(8))) {
$notification->time_period = 'last 7 days';
} else {
$notification->time_period = 'older';
}
return $notification;
});
return $this->success(['pagination' => $pagination]);
}
public function markAsRead()
{
$this->validate($this->request, [
'ids' => 'required|array',
]);
$now = Carbon::now();
$this->notification
->whereIn('id', $this->request->get('ids'))
->update(['read_at' => $now]);
$unreadCount = Auth::user()->unreadNotifications()->count();
return $this->success(['unreadCount' => $unreadCount, 'date' => $now]);
}
public function destroy($ids)
{
$ids = explode(',', $ids);
Auth::user()->notifications()->whereIn('id', $ids)->delete();
}
}