moataz/notify
Composer 安装命令:
composer require moataz/notify
包简介
A site notification package for laravel.
README 文档
README
A site notification package for laravel.
Currently let's you easily flash notifications to the session. It also supports laravels translation package out of the box.
Table of Contents
Installation
You can install the package for your Laravel project through Composer.
# Laravel 4x composer require andheiberg/notify:1.* # Laravel 5x composer require andheiberg/notify:2.*
Register the service provider in app/config/app.php.
Andheiberg\Notify\NotifyServiceProvider::class,
Add the alias to the list of aliases in app/config/app.php.
'Notify' => Andheiberg\Notify\Facades\Notify::class,
Configuration
The packages provides you with some configuration options.
To create the configuration file run this command in your command line app:
# Laravel 4x php artisan config:publish andheiberg/notify # Laravel 5x php artisan vendor:publish --provider="Andheiberg\Notify\NotifyServiceProvider"
The configuration file will be published here: app/config/packages/andheiberg/notify/config.php.
Usage
Adding Notifications
By default, the package has some notification types defined in its configuration file. The default types are success, error, warning and info.
Every type can be called as a function.
Notify::info('This is an info message.'); Notify::error('Whoops, something has gone wrong.');
You can of course add your own types by adding them to your own config file. See above on how to publish the config file.
You can also pass a language tag for easy localization.
Notify::success('auth.login-successful'); // Calls Lang::get('auth.login-successful') behind the scene Notify::warning('auth.verification-email-sent', ['email' => 'test@gmail.com']) // You can also pass replacements
Displaying Notifications
Notify class is just an extension of Illuminate's MessageBag class, which means we can use all of its functionality to display messages.
@foreach (Notify::all() as $notification) {{ $notification }} @endforeach
Or if you'd like to display a single notification for a certain level.
@if (Notify::has('success')) {{ Notify::first('success') }} @endif
If you'd like to learn more ways on how you can display messages, please take a closer look to Illuminate's MessageBag class.
Bootstrap example
@if (Notify::all()) <div class="container"> @foreach (Notify::get('success') as $alert) <div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert">×</button> {{ $alert }} </div> @endforeach @foreach (Notify::get('error') as $alert) <div class="alert alert-danger"> <button type="button" class="close" data-dismiss="alert">×</button> {{ $alert }} </div> @endforeach @foreach (Notify::get('info') as $alert) <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> {{ $alert }} </div> @endforeach @foreach (Notify::get('warning') as $alert) <div class="alert alert-warning"> <button type="button" class="close" data-dismiss="alert">×</button> {{ $alert }} </div> @endforeach </div> @endif
moataz/notify 适用场景与选型建议
moataz/notify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 178 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 moataz/notify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moataz/notify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 178
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-10-21