THIS PACKAGE IS DEPRECATED, PLEASE USE PHPFlasher INSTEAD
👀 This package helps you to add toastr.js notifications to your Laravel 5 and Lumen projects.
THIS PACKAGE IS DEPRECATED, CONSIDER USING PHPFlasher INSTEAD
You can install the package using composer
composer require yoeunes/toastrThen add the service provider to config/app.php. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
'providers' => [
...
Yoeunes\Toastr\ToastrServiceProvider::class
...
];As optional if you want to modify the default configuration, you can publish the configuration file:
php artisan vendor:publish --provider="Yoeunes\Toastr\ToastrServiceProvider"For Windows users if you get Unable to locate publishable resources
Run this command :
php artisan vendor:publishAnd after that select Yoeunes\Toastr\ToastrServiceProvider
The usage of this package is very simple and straightforward. it only required one step to use it :
Use toastr() helper function inside your controller to set a toast notification for info, success, warning or error
// Display an info toast with no title
toastr()->info('Are you the 6 fingered man?')As an example:
<?php
namespace App\Http\Controllers;
use App\Post;
use App\Http\Requests\PostRequest;
use Illuminate\Database\Eloquent\Model;
class PostController extends Controller
{
public function store(PostRequest $request)
{
$post = Post::create($request->only(['title', 'body']));
if ($post instanceof Model) {
toastr()->success('Data has been saved successfully!');
return redirect()->route('posts.index');
}
toastr()->error('An error has occurred please try again later.');
return back();
}
}// Set a warning toast, with no title
toastr()->warning('My name is Inigo Montoya. You killed my father, prepare to die!')
// Set a success toast, with a title
toastr()->success('Have fun storming the castle!', 'Miracle Max Says')
// Set an error toast, with a title
toastr()->error('I do not think that word means what you think it means.', 'Inconceivable!')
// Override global config options from 'config/toastr.php'
toastr()->success('We do have the Kapua suite available.', 'Turtle Bay Resort', ['timeOut' => 5000])You can also chain multiple messages together using method chaining
toastr()->info('Are you the 6 fingered man?')->success('Have fun storming the castle!')->warning('doritos');You can use toastr('') instead of toastr()->success()
function toastr(string $message = null, string $type = 'success', string $title = '', array $options = []);So
toastr($message)is equivalent totoastr()->success($message)toastr($message, 'info')is equivalent totoastr()->info($message)toastr($message, 'warning')is equivalent totoastr()->warning($message)toastr($message, 'error')is equivalent totoastr()->error($message)
// config/toastr.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Toastr options
|--------------------------------------------------------------------------
|
| Here you can specify the options that will be passed to the toastr.js
| library. For a full list of options, visit the documentation.
|
*/
'options' => [
'closeButton' => true,
'closeClass' => 'toast-close-button',
'closeDuration' => 300,
'closeEasing' => 'swing',
'closeHtml' => '<button><i class="icon-off"></i></button>',
'closeMethod' => 'fadeOut',
'closeOnHover' => true,
'containerId' => 'toast-container',
'debug' => false,
'escapeHtml' => false,
'extendedTimeOut' => 10000,
'hideDuration' => 1000,
'hideEasing' => 'linear',
'hideMethod' => 'fadeOut',
'iconClass' => 'toast-info',
'iconClasses' => [
'error' => 'toast-error',
'info' => 'toast-info',
'success' => 'toast-success',
'warning' => 'toast-warning',
],
'messageClass' => 'toast-message',
'newestOnTop' => false,
'onHidden' => null,
'onShown' => null,
'positionClass' => 'toast-top-right',
'preventDuplicates' => true,
'progressBar' => true,
'progressClass' => 'toast-progress',
'rtl' => false,
'showDuration' => 300,
'showEasing' => 'swing',
'showMethod' => 'fadeIn',
'tapToDismiss' => true,
'target' => 'body',
'timeOut' => 5000,
'titleClass' => 'toast-title',
'toastClass' => 'toast',
],
];For a list of available options, see toastr.js' documentation.
MIT




