andheiberg / notify
此包最新版本(2.0.0)没有提供许可信息。
laravel 网站通知包。
2.0.0
2015-08-27 10:03 UTC
Requires
- php: >=5.3.0
- illuminate/config: >=4.0.0, <6.0.0
- illuminate/session: >=4.0.0, <6.0.0
- illuminate/support: >=4.0.0, <6.0.0
- illuminate/translation: >=4.0.0, <6.0.0
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-09-14 15:27:05 UTC
README
laravel 网站通知包。
当前版本允许您轻松地将通知闪现到会话中。它还支持laravels的翻译包。
目录
安装
您可以通过Composer安装此包到您的Laravel项目。
# Laravel 4x composer require andheiberg/notify:1.* # Laravel 5x composer require andheiberg/notify:2.*
在app/config/app.php
中注册服务提供者。
Andheiberg\Notify\NotifyServiceProvider::class,
在app/config/app.php
中将别名添加到别名列表中。
'Notify' => Andheiberg\Notify\Facades\Notify::class,
配置
此包提供了一些配置选项。
在命令行应用中运行以下命令以创建配置文件:
# Laravel 4x php artisan config:publish andheiberg/notify # Laravel 5x php artisan vendor:publish --provider="Andheiberg\Notify\NotifyServiceProvider"
配置文件将发布到此处:app/config/packages/andheiberg/notify/config.php
。
使用
添加通知
默认情况下,此包在其配置文件中定义了一些通知类型。默认类型是 success
、error
、warning
和 info
。
每种类型都可以作为一个函数调用。
Notify::info('This is an info message.'); Notify::error('Whoops, something has gone wrong.');
当然,您可以通过将它们添加到自己的配置文件中来添加自己的类型。有关如何发布配置文件的说明,请参阅上面。
您还可以传递一个语言标签以方便本地化。
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
显示通知
Notify
类是 Illuminate 的 MessageBag
类的扩展,这意味着我们可以使用其所有功能来显示消息。
@foreach (Notify::all() as $notification) {{ $notification }} @endforeach
或者,如果您想显示某个级别的单个通知。
@if (Notify::has('success')) {{ Notify::first('success') }} @endif
如果您想了解更多关于如何显示消息的方法,请查看 Illuminate 的 MessageBag
类。
Bootstrap 示例
@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