arthurguy/notifications

通知

1.0.0 2015-06-16 22:19 UTC

This package is auto-updated.

Last update: 2024-09-24 04:30:58 UTC


README

安装

首先,通过Composer拉取包。

"require": {
    "arthurguy/notifications": "~1.0"
}

然后,如果使用Laravel 5,在app/config/app.php中包含服务提供者。

'providers' => [
    'ArthurGuy\Notifications\NotificationServiceProvider'
];

为了方便,可以在同一文件的底部添加一个外观别名

'aliases' => [
    'Flash' => 'ArthurGuy\Notifications\NotificationFacade'
];

用法

在你的控制器中,在执行重定向之前...

public function store()
{
    Notification::message('Welcome Aboard!');

    return Redirect::home();
}

您也可以这样做

  • Notification::info('消息')
  • Notification::success('消息')
  • Notification::error('消息')
  • Notification::warning('消息')

再次提醒,如果使用Laravel,这将设置几个会话键

  • 'flash_notification.message' - 您要闪现的消息
  • 'flash_notification.details' - 一个MessageBag对象,非常适合字段错误消息
  • 'flash_notification.level' - 表示通知类型的字符串(适用于应用HTML类名)

或者,如果您使用Laravel,您还可以使用flash()辅助函数来引用外观。以下是一个示例

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    notification()->success('You have been logged out.');

    return home();
}

或者,对于一般的信息闪现,只需这样做:notification('一些消息');

将此消息闪现到会话中后,您现在可以在视图(们)中显示它。可能像这样

@if (Session::has('flash_notification.message'))
    <div class="alert alert-{{ Session::get('flash_notification.level') }}">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

        {{ Session::get('flash_notification.message') }}
    </div>
@endif