elektronika_bagisto/packages/Webkul/Notification/src/Http/Controllers/Admin/NotificationController.php

118 lines
2.7 KiB
PHP
Raw Normal View History

2021-12-30 13:30:13 +00:00
<?php
namespace Webkul\Notification\Http\Controllers\Admin;
use Illuminate\Routing\Controller;
use Webkul\Notification\Repositories\NotificationRepository;
class NotificationController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* NotificationRepository
*
* @var object
*/
protected $notificationRepository;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(NotificationRepository $notificationRepository)
{
$this->notificationRepository = $notificationRepository;
$this->middleware('admin');
$this->_config = request('_config');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
return view($this->_config['view']);
}
/**
* Display a listing of the resource.
*
* @return array
*/
public function getNotifications()
{
$params = request()->all();
$searchResults = [];
if(isset($params) && isset($params['page'])){
unset($params['page']);
}
if(isset($params) && $params != NULL){
$searchResults = $this->notificationRepository->getParamsData($params);
}else{
2021-12-31 12:57:34 +00:00
$searchResults = $this->notificationRepository->with('order')->latest()->paginate(10);
2021-12-30 13:30:13 +00:00
}
return [
'search_results' => $searchResults,
'total_unread' => $this->notificationRepository->where('read',0)->count()
];
}
/**
* Update the notification is readed or not
*
* @return \Illuminate\View\View
*/
public function viewedNotifications($orderId){
if($notification = $this->notificationRepository->where('order_id',$orderId)->first()){
$notification->read = 1;
$notification->save();
return redirect()->route('admin.sales.orders.view',$orderId);
}
abort(404);
}
/**
* Update the notification is readed or not
*
* @return array
*/
public function readAllNotifications(){
$this->notificationRepository->where('read',0)->update(['read' => 1]);
$params = [
"limit" => 5,
"read" => 0
];
$searchResults = $this->notificationRepository->getParamsData($params);
return [
'search_results' => $searchResults,
'total_unread' => $this->notificationRepository->where('read',0)->count(),
'success_message' => trans('admin::app.notification.notification-marked-success')
];
abort(404);
}
}