edvinaskrucas/notification
Composer 安装命令:
composer require edvinaskrucas/notification
包简介
Package for Laravel for helping to manage flash / instant notifications / messages.
README 文档
README
Package is looking for maintainers Please contact me if interested.
Notification package for Laravel4 / Laravel5
A simple notification management package for Laravel4.
- Notification containers
- Notification collections
- Notification messages
- Formats for notifications
- Flash / instant notifications
- Method chaining
- Message positioning
Installation
Just place require new package for your laravel installation via composer.json
"edvinaskrucas/notification": "5.*"
Then hit composer update
Version matrix
| Laravel Version | Package version |
|---|---|
| = 5.4 | 5.2.* |
| >= 5.1 | 5.1.* |
| >= 5.0, < 5.1 | 5.0.* |
| >= 4, < 5 | >= 2, <= 3 |
Registering to use it with laravel
Add following lines to app/config/app.php
ServiceProvider array
\Krucas\Notification\NotificationServiceProvider::class,
Kernel middleware array (must be placed after 'Illuminate\Session\Middleware\StartSession' middleware)
\Krucas\Notification\Middleware\NotificationMiddleware::class,
Now you are able to use it with Laravel4.
Publishing config file
If you want to edit default config file, just publish it to your app folder.
php artisan vendor:publish --provider="\Krucas\Notification\NotificationServiceProvider" --tag="config"
Usage
Default usage
Adding message to default container.
\Krucas\Notification\Facades\Notification::success('Success message'); \Krucas\Notification\Facades\Notification::error('Error message'); \Krucas\Notification\Facades\Notification::info('Info message'); \Krucas\Notification\Facades\Notification::warning('Warning message');
Containers
Containers allows you to set up different containers for different placeholders.
You can pass closure to modify containers, simply use this syntax showed below
\Krucas\Notification\Facades\Notification::container('myContainer', function($container) { $container->info('Test info message'); $container->error('Error'); });
Also you can access container like this
\Krucas\Notification\Facades\Notification::container('myContainer')->info('Info message');
Method chaining
\Krucas\Notification\Facades\Notification::container('myContainer')->info('Info message')->error('Error message');
If you want to use default container just use null as container name. Name will be taken from config file.
\Krucas\Notification\Facades\Notification::container()->info('Info message');
Instant notifications (shown in same request)
Library supports not only flash messages, if you want to show notifications in same request just use
\Krucas\Notification\Facades\Notification::successInstant('Instant success message');
Custom single message format
Want a custom format for single message? No problem
\Krucas\Notification\Facades\Notification::success('Success message', 'Custom format :message');
Also you can still pass second param (format), to format messages, but you can format individual messages as shown above.
Add message as object
You can add messages as objects
\Krucas\Notification\Facades\Notification::success( \Krucas\Notification\Facades\Notification::message('Sample text') );
When adding message as object you can add additional params to message
\Krucas\Notification\Facades\Notification::success( \Krucas\Notification\Facades\Notification::message('Sample text')->format(':message') );
Add message as closure
You can add messages by using a closure
\Krucas\Notification\Facades\Notification::success(function (Message $message) { $message->setMessage('Sample text')->setPosition(1); });
Accessing first notification from container
You can access and show just first notification in container
{!! \Krucas\Notification\Facades\Notification::container('myContainer')->get('success')->first() !!}
Accessing first notification from all types
{!! \Krucas\Notification\Facades\Notification::container('myContainer')->all()->first() !!}
Displaying notifications
To display all notifications in a default container you need to add just one line to your view file
{!! \Krucas\Notification\Facades\Notification::showAll() !!}
When using showAll() you may want to group your messages by type, it can be done like this
{!! \Krucas\Notification\Facades\Notification::group('info', 'success', 'error', 'warning')->showAll() !!}
This will group all your messages in group and output it, also you can use just one, two or three groups.
Manipulating group output on the fly
\Krucas\Notification\Facades\Notification::addToGrouping('success')->removeFromGrouping('error');
Display notifications by type in default container, you can pass custom format
{!! \Krucas\Notification\Facades\Notification::showError() !!}
{!! \Krucas\Notification\Facades\Notification::showInfo() !!}
{!! \Krucas\Notification\Facades\Notification::showWarning() !!}
{!! \Krucas\Notification\Facades\Notification::showSuccess(':message') !!}
Displaying notifications in a specific container with custom format.
{!! \Krucas\Notification\Facades\Notification::container('myContainer')->showInfo(':message') !!}
Or you can just use blade extension
@notification() // will render default container @notification('custom') // will render 'custom' container
Message positioning
There is ability to add message to certain position.
// This will add message at 5th position \Krucas\Notification\Facades\Notification::info(Notification::message('info')->position(5)); \Krucas\Notification\Facades\Notification::info(Notification::message('info2')->position(1);
Clearing messages
You can clear all messages or by type.
\Krucas\Notification\Facades\Notification::clearError(); \Krucas\Notification\Facades\Notification::clearWarning(); \Krucas\Notification\Facades\Notification::clearSuccess(); \Krucas\Notification\Facades\Notification::clearInfo(); \Krucas\Notification\Facades\Notification::clearAll();
Add message and display it instantly in a view file
Want to add message in a view file and display it? Its very simple:
{!! \Krucas\Notification\Facades\Notification::container('myInstant')
->infoInstant('Instant message added in a view and displayed!') !!}
You can also add multiple messages
{!! \Krucas\Notification\Facades\Notification::container('myInstant')
->infoInstant('Instant message added in a view and displayed!')
->errorInstant('Error...') !!}
edvinaskrucas/notification 适用场景与选型建议
edvinaskrucas/notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 398.39k 次下载、GitHub Stars 达 520, 最近一次更新时间为 2013 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「flash」 「laravel」 「messages」 「instant」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 edvinaskrucas/notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 edvinaskrucas/notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 edvinaskrucas/notification 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Notification component for storing and retrieving flash data.
Shim repository for WebcamJS
Captures outgoing SMS notifications
A modern take on PHP session-based flash messages
A Laravel package made for displaying flashes messages in a conveniant way
统计信息
- 总下载量: 398.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 530
- 点击次数: 31
- 依赖项目数: 13
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-25