aitor24/notifier

Laravel 包,用于在前端轻松显示来自不同 JS 库的通知

安装次数: 20

依赖者: 0

建议者: 0

安全: 0

星标: 5

关注者: 2

分支: 0

开放问题: 0

类型:通知

1.0.1 2017-12-15 16:08 UTC

This package is not auto-updated.

Last update: 2024-09-19 02:00:27 UTC


README

Notifier

StyleCI Version License

Laravel 包,可轻松从 PHP 代码生成 js 通知

入门指南

注册服务提供者及别名

如果你使用的是 Laravel 5.5,则无需注册服务提供者或别名。否则,你应该这么做!

注册服务提供者

Aitor24\Notifier\NotifierServiceProvider::class,

注册别名

'Notifier' => Aitor24\Notifier\Facades\Notifier::class,

简单示例

<html>
    <head>
        <meta charset="utf-8">
        {!! Notifier::assets('sweetalert') !!}
    </head>
    <body>
        <!-- your content -->

        {!! Notifier::notify('Permission denied', 'error')->subtitle('You have not access to this site!') !!}
    </body>
</html>

捕获基本会话通知

如果你不想每次都调用 notify 函数,那么 all 函数就是你的解决方案。这个函数捕获所有基于会话的消息(成功、信息、错误和警告),你只需要按照以下示例在布局中放置代码即可。

控制器示例

你应该使用 ->with() 函数进行重定向,以便在会话中为下一个请求传递消息。

public function redirect()
{
    return redirect()->route('welcome')->with('success', 'All done!');
}

布局示例

然后你的布局应该与以下代码片段类似

<html>
    <head>
        <meta charset="utf-8">
        {!! Notifier::assets('sweetalert') !!}
    </head>
    <body>
        <!-- your content -->

        {!! Notifier::all('sweetalert') !!}
    </body>
</html>

函数 all() 可以不带参数调用,此时库将是配置的 config('notifier.defaults.library') 库。