Skip to content

Instantly share code, notes, and snippets.

@agarwa13
Created November 5, 2015 02:42
Show Gist options
  • Save agarwa13/289c19a00396ab3b2012 to your computer and use it in GitHub Desktop.
Save agarwa13/289c19a00396ab3b2012 to your computer and use it in GitHub Desktop.
Notification Service that manages an array in session. It allows us to specify notifications to send to the user in controllers and other locations conveniently.
<?php
/**
* Created by PhpStorm.
* User: Nikhil
* Date: 11/2/2015
* Time: 9:56 PM
*/
namespace App\Services;
use Session;
class Notification
{
/**
* Notification constructor.
* @param $notifications
*/
public function __construct()
{
if(!Session::has('notifications')){
Session::set('notifications',array());
}
}
/**
* @param $message
* @param string $type
*/
public function add_notification($message, $type = 'success'){
Session::push('notifications',['message' => $message, 'type' => $type]);
}
/**
* @return mixed
*/
public function getNotifications()
{
return Session::pull('notifications',array());
}
public function resetNotifications(){
Session::set('notifications',array());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment