NotificationController.php 1.72 KB
<?php namespace App\Http\Controllers;

use Auth;
use App\Models\Notification;

class NotificationController extends Controller {


	public function __construct()
	{
	  $this->middleware('auth');
	  $this->middleware('module_access');
	}

	public function index()
	{
	  $notifications=Notification::where("to","=",Auth::user()->username)->where("status","=","New")->orderBy('created_at')->get();
	  return view('layout.module.notification.index',array("notifications"=>$notifications));
	}
	public function create()
	{
		//
	}
	public function store()
	{
		//
	}
	public function show($id)
	{
	  if($id=="topbar")
	  {
	    $this->checkLiveRooms();
	  
	    $notifications=Notification::where("to","=",Auth::user()->username)->where("status","=","New")->orderBy('created_at','desc')->take(10)->get();
	    $count=Notification::where("to","=",Auth::user()->username)->where("status","=","New")->count();

	    $data=array();
	    foreach($notifications as $notification)
	    {
	      $data[]=array("sign"=>"+",
				  "type"=>$notification->type,
				  "text"=>$notification->data,
				  "tstr"=>date("d-M H:i",strtotime($notification->created_at)));
	    }
	    return view('layout.topbar.notification',array("notifications"=>$data,"notificationscount"=>$count));
	  }
	}
	public function edit($id)
	{
		//
	}
	public function update($id)
	{
		//
	}
	public function destroy($id)
	{
	  if($id=="clearall")
	  {
	    Notification::where("to","=",Auth::user()->username)->where("status","=","New")->update(array('status' => 'Archive'));
	    return view('layout.module.notification.index',array("notifications"=>array(),'displaymsg'=>array("type"=>"success","text"=>"All Notifications Cleared")));
	  }
	}


	public function dashboard()
	{
		//echo "OK";
	}

}