Toastr.js adapter for PHP flasher

Last updated at 08 May 2022 | Published at 28 November 2020

If you like PHPFlasher please consider giving it a on github or by spreading the word on twitter. Your support allows me to keep this package up-to-date and maintainable. Thank you


For more information about Toastr.js click here.

Installation

This package can be installed through Composer.

For Vanilla PHP:

composer require php-flasher/flasher-toastr

For Laravel:

composer require php-flasher/flasher-toastr-laravel

For Symfony:

composer require php-flasher/flasher-toastr-symfony

Usage

Just grave an instance of ToastrFactory and start calling build methods

namespace App\Controller;

use Flasher\Toastr\Prime\ToastrFactory;

class NotifyController
{
    public function flasher(ToastrFactory $flasher)
    {
        // ... 
        $flasher->addSuccess('Data has been saved successfully!');
        
        // ... redirect or render a view here
    }
}    

Fluent Builder methods

All methods in the Usage section are available also for ToastrFactory

title

The title of the notification

$flasher->title(string $title)

closeButton

Enable a close button

$flasher->closeButton(bool $closeButton = true)

closeClass

$flasher->closeClass(string $closeClass)

closeDuration

$flasher->closeDuration(int $closeDuration)

closeEasing

$flasher->closeEasing(string $closeEasing)

closeHtml

Override the close button’s HTML.

$flasher->closeHtml(string $closeHtml)

closeMethod

$flasher->closeMethod(string $closeMethod)

closeOnHover

$flasher->closeOnHover(bool $closeOnHover = true)

containerId

$flasher->containerId(string $containerId)

debug

$flasher->debug(bool $debug = true)

escapeHtml

In case you want to escape HTML characters in title and message

$flasher->escapeHtml(bool $escapeHtml = true)

extendedTimeOut

How long the toast will display after a user hovers over it

$flasher->extendedTimeOut(int $extendedTimeOut)

hideDuration

Specifies the time during which the pop-up closes in ms

$flasher->hideDuration(int $hideDuration)

hideEasing

Indicates the entry transition of the pop-up

$flasher->hideEasing(string $hideEasing)

hideMethod

Indicates the opening animation of the pop-up

$flasher->hideMethod(string $hideMethod)

iconClass

$flasher->iconClass(string $iconClass)

messageClass

$flasher->messageClass(string $messageClass)

newestOnTop

Show newest toast at bottom (top is default)

$flasher->newestOnTop(bool $newestOnTop = true)

onHidden

Define a callback for when the toast is hidden

$flasher->onHidden(string $onHidden)

onShown

Define a callback for when the toast is shown

$flasher->onShown(string $onShown)

positionClass

$flasher->positionClass(string $positionClass)

preventDuplicates

Rather than having identical toasts stack, set the preventDuplicates property to true. Duplicates are matched to the previous toast based on their message content.

$flasher->preventDuplicates(bool $preventDuplicates = true)

progressBar

Visually indicate how long before a toast expires.

$flasher->progressBar(bool $progressBar = true)

progressClass

$flasher->progressClass(string $progressClass)

rtl

Flip the toastr to be displayed properly for right-to-left languages.

$flasher->rtl(bool $rtl = true)

showDuration

Specifies the time during which the pop-up opens in ms

$flasher->showDuration(int $showDuration)

showEasing

Indicates the entry transition of the pop-up

$flasher->showEasing(string $showEasing)

showMethod

Indicates the opening animation of the pop-up

$flasher->showMethod(string $showMethod)

tapToDismiss

Forces the user to validate the pop-up before closing

$flasher->tapToDismiss(bool $tapToDismiss = true)

target

$flasher->target(string $target)

timeOut

How long the toast will display without user interaction

$flasher->timeOut(int $timeOut, bool $extendedTimeOut = null)

titleClass

$flasher->titleClass(string $titleClass)

toastClass

$flasher->toastClass(string $toastClass)

persistent

Prevent from Auto Hiding

$flasher->persistent()
Younes

PHPFlasher is a project by Younes KHOUBZA.