usernotnull/tall-toasts
Composer 安装命令:
composer require usernotnull/tall-toasts
包简介
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!
关键字:
README 文档
README
Beautiful Notification Toasts For Laravel & Livewire
A Toast global that can be called from the backend (via Controllers, Blade Views, Components) or frontend (JS, Alpine Components) to render customizable toasts.
Runs with the TALL stack: Laravel, TailwindCSS, Livewire, AlpineJS.
| Light | Dark |
|---|---|
![]() |
![]() |
Featured On
Why
If you are building a web app with the TALL stack, you must choose this library over the other outdated libraries available:
Size does matter
Since the frontend is a pure AlpineJS component with no reliance on external JS libs, and since the backend handles most of the logic, the javascript footprint is tiny (less than ONE kilobyte!) .
The CSS footprint is also negligible as it uses the default TailwindCSS classes. Even if you override the default views, you will rest assured that Tailwind's purging will only keep the styles/classes you have used.
In plain English, it will not bloat your generated JS/CSS files nor add extra files to download as when using other JS libs!
Takes advantage of all the niceties that come with TALL
You can call it from anywhere! Memorize Toast for the frontend and toast() for the backend.
See the usage section for examples.
Customizable
You have control over the view: As you are overriding the blade view, you'll be able to shape it as you like using TailwindCSS classes.
No more messing with custom CSS overrides!
Usage
From The Frontend
Toast.info('Notification from the front-end...', 'The Title'); Toast.success('A toast without a title also works'); Toast.warning('Watch out!'); Toast.danger('I warned you!', 'Yikes'); Toast.debug('I will NOT show in production! Locally, I will also log in console...', 'A Debug Message'); Toast.success('This toast will display only for 3 seconds', 'The Title', 3000); Toast.success('This toast will display until you remove it manually', 'The Title', 0);
From The Backend
toast() ->info('I will appear only on the next page!') ->pushOnNextPage(); toast() ->info('Notification from the backend...', 'The Title') ->push(); toast() ->success('A toast without a title also works') ->push(); toast() ->warning('Watch out!') ->push(); toast() ->danger('I warned you!', 'Yikes') ->push(); toast() ->danger('I will go…<br><i>to the next line 💪</i>', 'I am <span style="color:red;">HOT</span>') ->doNotSanitize() ->push(); toast() ->debug('I will NOT show in production! Locally, I will also log in console...', 'A Debug Message') ->push(); // debug also accepts objects as message toast() ->debug(User::factory()->createOne()->only(['name', 'email']), 'A User Dump') ->push(); toast() ->success('This toast will display only for 3 seconds') ->duration(3000) ->push(); toast() ->success('This toast will display until you remove it manually') ->sticky() ->push();
You can call the above toast helper from controllers, blade views, and components.
Support Me
I plan on developing many open-source packages using the TALL stack.
Consider supporting my work by tweeting about this library or by contributing to this package.
Check out the list of other packages I built for the TALL stack Other Packages.
To stay updated, follow me on Twitter.
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.0 |
| Laravel | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0 |
| TailwindCSS | ^2.0 | ^3.0 |
| Livewire | ^2.0 | ^3.0 (as of tall-toasts v2) |
| AlpineJS | ^3.0 |
You can find the older v1 documentation here
Installation
You can install the package via Composer:
composer require usernotnull/tall-toasts
Setup
TailwindCSS
Build your CSS as you usually do, ie
npm run dev
Usage With Tailwind JIT
If you are using Just-in-Time Mode, add these additional lines into
your tailwind.config.js file:
// use `purge` instead of `content` if using TailwindCSS v2.x content: [ './vendor/usernotnull/tall-toasts/config/**/*.php', './vendor/usernotnull/tall-toasts/resources/views/**/*.blade.php', // etc... ]
This way, Tailwind JIT will include the classes used in this library in your CSS.
As usual, if the content of tailwind.config.js changes, you should re-run the npm command.
Registering Toast with AlpineJS
Add the Toast component in your app.js:
import {Alpine, Livewire} from '../../vendor/livewire/livewire/dist/livewire.esm'; import ToastComponent from '../../vendor/usernotnull/tall-toasts/resources/js/tall-toasts' Alpine.plugin(ToastComponent) Livewire.start()
Add <livewire:toasts /> as high as possible in the body tag, ie:
<!DOCTYPE html> <html lang="en"> <head> <!-- Metas, Styles, JS... --> </head> <body> <livewire:toasts /> <!-- Below toasts, your contents... --> @livewireScriptConfig </body> </html>
To properly dispatch toasts from inside your livewire components, add the trait:
use Livewire\Component; use Usernotnull\Toast\Concerns\WireToast; class DemoComponent extends Component { use WireToast; // <-- add this public function sendCookie(): void { toast() ->success('You earned a cookie! 🍪') ->pushOnNextPage(); redirect()->route('dashboard'); }
That's it! 🎉
RTL Support
The default layout now supports RTL.
As per TailwindCSS docs on RTL support:
Always set the direction, even if left-to-right is your default.
<html dir="ltr"> <!-- ... --> </html>
Customization
The toasts should look pretty good out of the box. However, we've documented a couple of ways to customize the views and functionality.
Configuration
You can publish the config file with:
php artisan vendor:publish --provider="Usernotnull\Toast\ToastServiceProvider" --tag="tall-toasts-config"
These are the default contents of the published config file:
<?php return [ /* * How long each toast will be displayed before fading out, in ms */ 'duration' => 5000, /* * How long to wait before displaying the toasts after page loads, in ms */ 'load_delay' => 400, ];
Customizing views
You can publish and change all views in this package:
php artisan vendor:publish --provider="Usernotnull\Toast\ToastServiceProvider" --tag="tall-toasts-views"
The published views can be found and changed in resources/views/vendor/tall-toast/.
The published files are:
includes/content.blade.php- the content view of each popup notification, fully configurableincludes/icon.blade.php- the icons of each notification typelivewire/toasts.blade.php- the parent of all toasts
Text Sanitization
The content view displays the title and message with x-html. This is fine since the backend sanitizes the title and message by default.
⚠️ If you wish to skip sanitization in order to display HTML content, such as bolding the text or adding <br> to go to
the next line, you will call doNotSanitize() as seen in the usage section. In such case, make sure no user
input is provided!
Troubleshooting
Make sure you thoroughly go through this readme first!
If the checklist below does not resolve your problem, feel free to submit an issue. Make sure to follow the bug report template. It helps us quickly reproduce the bug and resolve it.
The toasts show multiple times only after refresh
-
If you are calling toasts from a livewire component, did you add the trait WireToast to the component? (see)
-
Did you swap push() and pushOnNextPage()?
The toasts won't show
-
Is the <livewire:toasts /> located in a page that has both the livewire and alpine/app.js script tags inserted?
-
Did you skip adding the ToastComponent as an alpine data component?
-
Did you forget calling push() at the end of the chained method? (see)
-
Have you tried calling the toast() helper function from another part of the application and check if it worked (it will help us scope the problem)? (see)
-
Did you try calling
php artisan view:clear? -
Are you getting any console errors?
The toasts show but look weird
- Are you using TailwindCSS JIT? Don't forget to update your purge list! (see)
- You may need to rebuild your CSS by running:
npm run devor re-runningnpm run watch(see)
Other Packages
To stay updated, follow me on Twitter.
Testing
This package uses PestPHP to run its tests.
- To run tests without coverage, run:
composer test
- To run tests with coverage, run:
composer test-coverage
Contributing
This package has 3 GitHub Workflows which run sequentially when pushing PRs:
-
First, it checks for styling issues and automatically fixes them using:
-
Then, it uses static analysis followed by standard unit tests using:
-
Finally, it generates the minified JS dist which is injected by @toastScripts
When pushing PRs, it's a good idea to do a quick run and make sure the workflow checks out, which saves time during code review before merging.
To facilitate the job, you can run the below command before pushing the PR:
composer workflow
Please see CONTRIBUTING for details.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Versioning
This project follows the Semantic Versioning guidelines.
Security Vulnerabilities
As per security best practices, do not call doNotSanitize() on a toast that has user input in its message or title!
Please review the security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see the license file for more information.
usernotnull/tall-toasts 适用场景与选型建议
usernotnull/tall-toasts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 413.53k 次下载、GitHub Stars 达 569, 最近一次更新时间为 2021 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-package」 「tailwindcss」 「toast-notifications」 「livewire」 「alpinejs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 usernotnull/tall-toasts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 usernotnull/tall-toasts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 usernotnull/tall-toasts 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
TitleWithSlugInput - Easy Permalink Slugs for the FilamentPHP Form Builder (PHP / Laravel / Livewire)
TailwindPHP - use Tailwind CSS in your PHP projects (without npm)
A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.
Vanilla Components Integration with Laravel
Laravel table comments loader (part of Diplodocker project)
jitone-ai is a powerful FilamentPHP plugin that integrates AI-powered features directly into your Filament forms.
统计信息
- 总下载量: 413.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 569
- 点击次数: 32
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-11

