在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):edvinaskrucas/notification开源软件地址(OpenSource Url):https://github.com/edvinaskrucas/notification开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Package is looking for maintainers Please contact me if interested. Notification package for Laravel4 / Laravel5A simple notification management package for Laravel4.
InstallationJust place require new package for your laravel installation via composer.json
Then hit Version matrix
Registering to use it with laravelAdd following lines to ServiceProvider array \Krucas\Notification\NotificationServiceProvider::class, Kernel middleware array ( \Krucas\Notification\Middleware\NotificationMiddleware::class, Now you are able to use it with Laravel4. Publishing config fileIf you want to edit default config file, just publish it to your app folder.
UsageDefault usageAdding 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'); ContainersContainers 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 \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 formatWant 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 objectYou 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 closureYou 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 containerYou 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 notificationsTo 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 {!! \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 positioningThere 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 messagesYou 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 fileWant 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...') !!} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论