retinens / laravel-bootstrap-toasts
This package provides an easy interface for using Bootstrap 5+ toast messages in a Laravel app.
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-12-09 08:13:03 UTC
README
This package provides an easy interface for using Bootstrap 5.2+ toast messages in a Laravel app.
Installation
You can install the package via composer:
composer require retinens/laravel-toastr
You can publish the config file with:
php artisan vendor:publish --tag="laravel-toastr-config"
This is the contents of the published config file:
return [ /* * Defines the default auto_hide parameter */ 'auto_hide' => false, /* * Defines the position of the toast on the window */ // "top" or "bottom" "position_y" => 'bottom', // "start" or "end" "position_x" => 'end', ];
Optionally, you can publish the views using
php artisan vendor:publish --tag="laravel-toastr-views"
Usage
Bootstrap should be imported in your assets and available in the window variable.
window.bootstrap = require("bootstrap");
First, include this snippet in your Blade template
<x-boostrap-toastr/>
Then, in your controller, call the toast()
method to create a toast message.
public function edit() { toast('Post edited!'); return redirect(route('posts.list')); }
The toast method accepts the title and level as optional arguments :
toast('message','level','title')
There are a few quick methods to modify the toast:
-
toast('Message')->success()
: Set the toast level as "success". -
toast('Message')->info()
: Set the toast level as "info". -
toast('Message')->error()
: Set the toast level as "danger". -
toast('Message')->warning()
: Set the toast level as "warning". -
toast('Message')->title("Toast title")
: Set the toast title. -
toast('Message')->important()
: Add a close button to the toast.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.