masterro/laravel-flashes

轻松使用闪存消息

v1.5.0 2024-03-22 14:08 UTC

This package is auto-updated.

Last update: 2024-09-22 15:16:11 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

StandWithUkraine

Laravel的轻松闪存消息

快速的闪存消息集成。

安装

在命令行中运行

composer require masterro/laravel-flashes

使用方法

在某个地方设置闪存消息

  • flash("Hello, {$name}!");
  • flash("Hello, {$name}!", 'success');
  • flash()->error($message); // ->success(), ->info(), ->warning(), ->error()
  • flash()->with(['body' => 'My custom body text']); // ->success(), ->info(), ->warning(), ->error()
  • Flash::info('Flash!');

在关闭 </body> 标签之前

@include('flash-messages::script')

或者 实现自己的渲染逻辑

php artisan vendor:publish --tag=flash-messages-views

实现通知方法(以bootstrap-notify为例)

包将触发全局javascript函数 window.notify(message, type),您应该实现它。以下是一个bootstrap-notify实现的示例

window.notify = (message, type = 'success', options = {}) => {
    if (type === 'error') {
        type = 'danger';
    }

    return window.$.notify(window._.merge({
        message: message
    }, options), {
        type: type,
        animate: {
            enter: 'animated bounceIn',
            exit: 'animated bounceOut'
        },
        z_index: 9999,
        delay: 7000,
        mouse_over: 'pause',
        offset: {
            x: 20,
            y: 30
        }
    });
};

它需要 bootstrapbootstrap-notifyanimate.css 您可以使用yarn或npm进行安装和引用

yarn add bootstrap-notifynpm i bootstrap-notify --save