Notification package for Laravel

Overview

Package is looking for maintainers Please contact me if interested.

Notification package for Laravel4 / Laravel5

Build Status


A simple notification management package for Laravel4.


  • Notification containers
  • Notification collections
  • Notification messages
  • Formats for notifications
  • Flash / instant notifications
  • Method chaining
  • Message positioning

Installation

Just place require new package for your laravel installation via composer.json

"edvinaskrucas/notification": "5.*"

Then hit composer update

Version matrix

Laravel Version Package version
= 5.4 5.2.*
>= 5.1 5.1.*
>= 5.0, < 5.1 5.0.*
>= 4, < 5 >= 2, <= 3

Registering to use it with laravel

Add following lines to app/config/app.php

ServiceProvider array

\Krucas\Notification\NotificationServiceProvider::class,

Kernel middleware array (must be placed after 'Illuminate\Session\Middleware\StartSession' middleware)

\Krucas\Notification\Middleware\NotificationMiddleware::class,

Now you are able to use it with Laravel4.

Publishing config file

If you want to edit default config file, just publish it to your app folder.

php artisan vendor:publish --provider="\Krucas\Notification\NotificationServiceProvider" --tag="config"

Usage

Default usage

Adding message to default container.

\Krucas\Notification\Facades\Notification::success('Success message');
\Krucas\Notification\Facades\Notification::error('Error message');
\Krucas\Notification\Facades\Notification::info('Info message');
\Krucas\Notification\Facades\Notification::warning('Warning message');

Containers

Containers allows you to set up different containers for different placeholders.

You can pass closure to modify containers, simply use this syntax showed below

\Krucas\Notification\Facades\Notification::container('myContainer', function($container)
{
    $container->info('Test info message');
    $container->error('Error');
});

Also you can access container like this

\Krucas\Notification\Facades\Notification::container('myContainer')->info('Info message');

Method chaining

\Krucas\Notification\Facades\Notification::container('myContainer')->info('Info message')->error('Error message');

If you want to use default container just use null as container name. Name will be taken from config file.

\Krucas\Notification\Facades\Notification::container()->info('Info message');

Instant notifications (shown in same request)

Library supports not only flash messages, if you want to show notifications in same request just use

\Krucas\Notification\Facades\Notification::successInstant('Instant success message');

Custom single message format

Want a custom format for single message? No problem

\Krucas\Notification\Facades\Notification::success('Success message', 'Custom format :message');

Also you can still pass second param (format), to format messages, but you can format individual messages as shown above.

Add message as object

You can add messages as objects

\Krucas\Notification\Facades\Notification::success(
    \Krucas\Notification\Facades\Notification::message('Sample text')
);

When adding message as object you can add additional params to message

\Krucas\Notification\Facades\Notification::success(
    \Krucas\Notification\Facades\Notification::message('Sample text')->format(':message')
);

Add message as closure

You can add messages by using a closure

\Krucas\Notification\Facades\Notification::success(function (Message $message) {
    $message->setMessage('Sample text')->setPosition(1);
});

Accessing first notification from container

You can access and show just first notification in container

{!! \Krucas\Notification\Facades\Notification::container('myContainer')->get('success')->first() !!}

Accessing first notification from all types

{!! \Krucas\Notification\Facades\Notification::container('myContainer')->all()->first() !!}

Displaying notifications

To display all notifications in a default container you need to add just one line to your view file

{!! \Krucas\Notification\Facades\Notification::showAll() !!}

When using showAll() you may want to group your messages by type, it can be done like this

{!! \Krucas\Notification\Facades\Notification::group('info', 'success', 'error', 'warning')->showAll() !!}

This will group all your messages in group and output it, also you can use just one, two or three groups.

Manipulating group output on the fly

\Krucas\Notification\Facades\Notification::addToGrouping('success')->removeFromGrouping('error');

Display notifications by type in default container, you can pass custom format

{!! \Krucas\Notification\Facades\Notification::showError() !!}
{!! \Krucas\Notification\Facades\Notification::showInfo() !!}
{!! \Krucas\Notification\Facades\Notification::showWarning() !!}
{!! \Krucas\Notification\Facades\Notification::showSuccess(':message') !!}

Displaying notifications in a specific container with custom format.

{!! \Krucas\Notification\Facades\Notification::container('myContainer')->showInfo(':message') !!}

Or you can just use blade extension

@notification() // will render default container

@notification('custom') // will render 'custom' container

Message positioning

There is ability to add message to certain position.

// This will add message at 5th position
\Krucas\Notification\Facades\Notification::info(Notification::message('info')->position(5));
\Krucas\Notification\Facades\Notification::info(Notification::message('info2')->position(1);

Clearing messages

You can clear all messages or by type.

\Krucas\Notification\Facades\Notification::clearError();
\Krucas\Notification\Facades\Notification::clearWarning();
\Krucas\Notification\Facades\Notification::clearSuccess();
\Krucas\Notification\Facades\Notification::clearInfo();
\Krucas\Notification\Facades\Notification::clearAll();

Add message and display it instantly in a view file

Want to add message in a view file and display it? Its very simple:

{!! \Krucas\Notification\Facades\Notification::container('myInstant')
        ->infoInstant('Instant message added in a view and displayed!') !!}

You can also add multiple messages

{!! \Krucas\Notification\Facades\Notification::container('myInstant')
        ->infoInstant('Instant message added in a view and displayed!')
        ->errorInstant('Error...') !!}
Comments
  • Does not work with Laravel 4.2

    Does not work with Laravel 4.2

    I am using essentially the same code from two projects. One of them doesn't work; and after a lot of trial and error as to why it doesn't - (the notifications do not show, and there are no errors) I have to conclude that it is because the latter project which doesn't show the notifications is running Laravel 4.2.

    opened by mstnorris 11
  • Redirecting and passing on messages

    Redirecting and passing on messages

    Firstly this is a great package - thank you for that.

    I suspect what I am trying to do is supported, but I can't quite see how. The situation is this:

    I have a landing page, which registers a notification message then redirects to a survey. That survey then does another redirect to take the user to the next page of that survey. In that second redirect, the initial notification is lost. I'm guessing the messages are cleared from the session on each page load, regardless of whether they are displayed or not.

    So is there a way to pass the messages on to the next page? i.e. a route that contains only a redirect is given a notification from the previous page, which it then needs to pass on to the final (third) page.

    opened by judgej 10
  • Does not show the notification

    Does not show the notification

    I have been set a notification in Controller Notification::warning('New password and confirm new password is mismatch !');

    And in the view blade {!! Notification::showAll() !!}

    But it seems does not show the notification because warning session is not set by Notification::warning

    opened by JFOC 8
  • Notification now showing

    Notification now showing

    Hey,

    for some reason it is not showing the added notifications. I am sure that it's not caused by the template, I think that it does not add it correctly. How can I check if it has been indeed added within the Controller itself?

    Thanks!

    opened by TheTechnoMan 8
  • Latest version of L5 breaks Notifications.

    Latest version of L5 breaks Notifications.

    I was using the Notifications package on an L5 test site I am tinkering with and it was working last week. Today, after a composer update this morning to latest L5 though, the Notifications no longer appear using {!! Notification::showAll() !!} on a blade view. Didn't change anything else yet, so I am pretty confident it was the latest L5 update. I can see the message container in the Session but haven't sorted out why they aren't appearing. I am going to keep digging at it, but thought I would let you know.

    when Notifications don't appear:

    \Session::all()

    array (size=4)
      '_token' => string 'A1etWkhS277ZJVQPrbGKsHzOJ3uKX8uT7gfBTbd3' (length=40)
      'flash' => 
        array (size=2)
          'old' => 
            array (size=0)
              empty
          'new' => 
            array (size=2)
              0 => string 'notifications_containers' (length=24)
              1 => string 'notifications_default_1' (length=23)
      'notifications_containers' => 
        array (size=1)
          0 => string 'default' (length=7)
      'notifications_default_1' => string '{"message":"Sorry, you can only send one message every 3 minutes","format":"<div class=\"alert alert-:type alert-dismissable\" id=\"flash_notice\">\r\n            <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;<\/button>\r\n            :message\r\n          <\/div>","type":"warning","flashable":true,"alias":null,"position":null}' (length=374)
    
    opened by landjea 7
  • Don't Understand

    Don't Understand

    I guess I don't entirely understand the usefullness of the default calls (Notification::success(...))...

    When would you NOT want to use successInstant instead? I don't understand the use case for the regular notification types... can someone fill me in?

    opened by kevinklika 6
  • It seems not compatible with laravel 4.1.x

    It seems not compatible with laravel 4.1.x

    when I run compose update, I get the failure notice like this:

    Problem 1 - Conclusion: remove laravel/framework 4.1.x-dev - edvinaskrucas/notification 1.0 requires illuminate/config 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4], illuminate/config[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4]. - edvinaskrucas/notification 1.0.1 requires illuminate/config 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4], illuminate/config[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4]. - edvinaskrucas/notification 1.1 requires illuminate/config 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4], illuminate/config[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4]. - edvinaskrucas/notification 1.1.1 requires illuminate/config 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4], illuminate/config[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4]. - edvinaskrucas/notification 1.2 requires illuminate/config 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4], illuminate/config[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4]. - Can only install one of: laravel/framework[4.1.x-dev, 4.0.x-dev]. - Can only install one of: laravel/framework[v4.0.0, 4.1.x-dev]. - Can only install one of: laravel/framework[v4.0.0-BETA2, 4.1.x-dev]. - Can only install one of: laravel/framework[v4.0.0-BETA3, 4.1.x-dev]. - Can only install one of: laravel/framework[v4.0.0-BETA4, 4.1.x-dev]. - don't install illuminate/config 4.0.x-dev|don't install laravel/framework 4.1.x-dev - don't install illuminate/config v4.0.0|don't install laravel/framework 4.1.x-dev - don't install illuminate/config v4.0.0-BETA2|don't install laravel/framework 4.1.x-dev - don't install illuminate/config v4.0.0-BETA3|don't install laravel/framework 4.1.x-dev - don't install illuminate/config v4.0.0-BETA4|don't install laravel/framework 4.1.x-dev - Installation request for laravel/framework 4.1.* -> satisfiable by laravel/framework[4.1.x-dev]. - Installation request for edvinaskrucas/notification 1.* -> satisfiable by edvinaskrucas/notification[1.0, 1.0.1, 1.1, 1.1.1, 1.2].

    opened by ghost 6
  • Laravel 5.8 Support

    Laravel 5.8 Support

    Is this package still being maintained?

    I'm hitting the following issue with the latest Laravel release (5.8).

    1/4 in vendor/edvinaskrucas/notification/src/Krucas/Notification/Collection.php:6 "Declaration of Krucas\Notification\Collection::add(Krucas\Notification\Message $message) should be compatible with Illuminate\Support\Collection::add($item)
    
    opened by diggersworld 5
  • Fixes Laravel 5.4 wildcard event listening signature change

    Fixes Laravel 5.4 wildcard event listening signature change

    Laravel 5.4 has changed the way wildcard event subscribers work. They now receive the event name as their first argument and the array of event data as their second argument, meaning the method signature of Krucas\Notification\Subscriber::onFlash no longer works. This same issue has also been noted in #81.

    This pull request fixes this issue.

    I've created a repository and written instructions to help you replicate the bug and verify that this PR fixes the issue.

    opened by Harrisonbro 5
  • Array to string conversion error laravel 5.2

    Array to string conversion error laravel 5.2

    This:

    {!! Notification::showAll() !!}

    gives:

    Array to string conversion (View: /Users/matthijs/www/newdutchbridge/resources/views/frontend/basic/contact.blade.php)

    opened by matthijs-neijenhuijs 5
  • Not displaying notifications on Laravel 4.2

    Not displaying notifications on Laravel 4.2

    Hi all,

    Just updated my project from Laravel 4.0 to 4.2 and my notifications stopped working. I'm using "edvinaskrucas/notification": "3.*".

    Here are some examples of not working controllers return:

    Notification::success('success');
    return Redirect::back();
    
    Notification::success('success');
    return Redirect::to('orders');
    
    Notification::success('success');
    return Redirect::route('orders.create');
    

    On the view I simple use:

    {{ Notification::showAll() }}
    

    I have no more ideas how to debug that...

    opened by lucastaliberti 5
  • Tag Laravel 5.8.0 release

    Tag Laravel 5.8.0 release

    Would you be able to add the 5.8.0 release to the commit that is compatible with Laravel 5.8?

    The commit is:

    https://github.com/edvinaskrucas/notification/commit/65deec7255644100ba04802c561521ef57d9ec1e

    I realised we have been using dev-master for some time for the L 5.8 compatibility, and the L 6.0 updates have broken that. Thanks.

    opened by judgej 1
  • Add version 5.1.2 tag

    Add version 5.1.2 tag

    Hola Edvinas, Would you mind adding a new version tag to the lastest merged pull-request? This way I can switch my projects using Notifications back to your repo, instead of continuing to use my fork.

    Thanks, Niels

    opened by npostman 0
  • FR: save notifications over multiple redirects

    FR: save notifications over multiple redirects

    A notification will normally be available on the next page, and will subsequently be removed from the session after that.

    An instant notification will appear on the current page and will not even make it into the session.

    What does not seem to be covered, is saving the notifications for displaying several pages from now. For example, I set a notification, then redirect to the next page. That next page does a check which means it also needs to immediately redirect to another page. The notifications are lost in that second redirect. There needs to be a way to tell this package to hold on to the messages just one more page. Maybe there is a way, and I am just missing it?

    opened by judgej 3
Releases(5.2.0)
Owner
Edvinas Kručas
Edvinas Kručas
Notification package for Laravel

Package is looking for maintainers Please contact me if interested. Notification package for Laravel4 / Laravel5 A simple notification management pack

Edvinas Kručas 531 Oct 12, 2022
Livewire Package to display Toast Notification based on TALL Stack.

livewire-toast Livewire Package to display Toast Notification based on TALL Stack. Requirements Make sure that Livewire is installed properly on your

AscSoftwares 35 Nov 12, 2022
Multiple channels of laravel exception notification(DingTalk、FeiShu、ServerChan、WeWork、XiZhi). - 多种通道的 laravel 异常通知(钉钉群机器人、飞书群机器人、Server 酱、企业微信群机器人、息知)。

laravel-exception-notify 简体中文 | ENGLISH Multiple channels of laravel exception notification(DingTalk、FeiShu、ServerChan、WeWork、XiZhi). - 多种通道的 laravel

guanguans 61 Dec 8, 2022
@Authy notification channel for @Laravel, with the ability to send in-app, sms, and call verification tokens.

Authy Notification Channel for Laravel Authy notification channel for Laravel, with the ability to send in-app, sms, and call verification tokens. Tab

Laravel Notification Channels 57 Dec 19, 2022
Google Chat - Laravel Notification Channel

Google Chat - Laravel Notification Channel This package makes it easy to send notifications using Google Chat , (formerly known as Hangouts Chat) with

Laravel Notification Channels 36 Dec 6, 2022
Laravel SMS Notification Channel

Laravel SMS Notification Channel Installation composer require guangda/laravel-sms-notification-channel env 配置 SMS_PROVIDER=yunpian SMS_SIGNATURE=【签名

Guangda 6 Dec 29, 2021
A Toast notification library for the Laravel TALL stack.

A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS ????

John F 365 Jan 7, 2023
Slack notification for Laravel as it should be. Easy, fast, simple and highly testable.

Based on illuminate/mail About Laravel Slack Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. Since it uses On-

Guilherme Pressutto 284 Aug 24, 2022
Lark Notification Channel for laravel.

Lark notifications channel for Laravel This package makes it easy to send Lark using the Laravel notification system. Supports 5.5+, 6.x, 7.x and 8.x.

null 1 Nov 3, 2021
AmaranJS stylish notification for your laravel application.

AmaranJS Laravel 5 Package AmaranJS L5 package is a Laravel wrapper for my jquery plugin AmaranJS.You can create easy and stylish notifications with A

Hakan ERSU 24 Oct 3, 2019
An SMS notification channel for the PHP framework Laravel.

Laravel SMS notification channel An SMS notification channel for the PHP framework Laravel. Supported SMS gateways: 46elks Cellsynt Telenor SMS Pro Tw

Andreas 2 Jan 22, 2022
Laravel notification manager

Easily manage notifications and notification subscriptions in your Laravel application.

Rubik 11 Aug 10, 2022
Laravel FCM (Firebase Cloud Messaging) Notification Channel

Laravel FCM Notification Laravel FCM (Firebase Cloud Messaging) Notification Channel Use this package to send push notifications via Laravel to Fireba

Vishal Dudhatra 3 Jul 3, 2022
ApnsPHP: Apple Push Notification & Feedback Provider

ApnsPHP: Apple Push Notification & Feedback Provider A full set of open source PHP classes to interact with the Apple Push Notification service for th

Immobiliare Labs 1.4k Nov 16, 2022
A filterable git commit summary notification mailer

Git commit notification A symfony application to allow receiving commit notification for all commits in a certain time period. Features: Receive one m

123inkt 4 Jan 3, 2023
Bootstrap 4 & 5 replacement for jGrowl notification

XoopsGrowl module for XOOPS CMS 2.5.11+ XoopsGrowl is a module for XOOPS CMS to configure an alternative to the jGrowl notification using Bootstrap Al

null 1 Oct 28, 2021
Bootstrap 4 & 5 replacement for jGrowl notification

XoopsGrowl module for XOOPS CMS 2.5.11+ XoopsGrowl is a module for XOOPS CMS to configure an alternative to the jGrowl notification using Bootstrap Al

null 1 Oct 24, 2021
WordPress Notification plugin

Notification This is the public repository for Notification - the WordPress plugin. This plugin allow you to send custom notifications about various e

BracketSpace 157 Nov 28, 2022
Laravel package to launch toast notifications.

Laravel package to launch toast notifications. This package provides assistance when using toast notifications. Using the iziTOAST package, which allo

Anthony Medina 7 Nov 25, 2022