nicoaudy/noty

为 Laravel 设计的优雅的 Flash 消息包装器

1.0.1 2020-07-16 03:04 UTC

This package is auto-updated.

Last update: 2024-09-07 16:13:53 UTC


README

License Latest Version on Packagist Total Downloads

这是一个优雅且可配置的通知包,用于在 Laravel 应用程序中发送 Flash 消息。Flash 消息是一种通过将消息存储在会话中传递到下一个请求的消息。

Screenshot

以下是使用方法

安装

您可以通过 composer 安装此包

composer require nicoaudy/noty

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Nicoaudy\Noty\NotyServiceProvider"

这是已发布配置文件的内容

return [
    /*
    * Title configuration color
    */
    'titleColor' => '',

    /*
    * Title configuration size
    */
    'titleSize' => '',

    /*
    * Title configuration line hight
    */
    'titleLineHeight' => '',

    /*
    * Message configuration color
    */
    'messageColor' => '',

    /*
    * Message configuration size
    */
    'messageSize' => '',

    /*
    * Message configuration line hight
    */
    'messageLineHeight' => '',

    /*
     * Positions:  bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
     */
    'position' => 'topRight',

    /*
     * Themes:  light, dark
     */
    'theme' => 'light',

    /*
     * Layout:  1 (title inline with message), 2 (title on top of message)
     */
    'layout' => 1,

    /*
    * [integer|boolean] - Delay for closing event in milliseconds. Set false for sticky notifications.
    */
    'timeout' => 4000,

    /*
     * [boolean] - Displays a progress bar.
     */
    'progressBar' => true,

    /*
     * [string] - Progress bar color
     */
    'progressBarColor' => 'rgb(0, 255, 184)',

    /*
     * [string] - Progress bar linear / ease
     */
    'progressBarEasing' => 'linear',

    /*
     * [boolean] - Balloon
     */
    'balloon' => true,

    /*
     * [boolean] - enable to close?
     */
    'close' => true,

    /*
     * [boolean] - Close on click
     */
    'closeOnClick' => false,

    /*
     * [boolean] - Close on escape?
     */
    'closeOnEscape' => false,

    /*
     * Animate inside
     */
    'animateInside' => true, // bool

    /*
     * Enable drag for close
     */
    'drag' => true, // bool

    /*
     * Pause on hover
     */
    'pauseOnHover' => true, // bool

    /*
     * Reset on hover
     */
    'resetOnHover' => false, // bool

    /*
     * [string] - Transition In
     * Default toast open animation. It can be: bounceInLeft, bounceInRight, bounceInUp, bounceInDown, fadeIn, fadeInDown, fadeInUp, fadeInLeft, fadeInRight or flipInX.
     */
    'transitionIn' => 'fadeInUp',

    /*
     * [string] - Transition Out
     * Default toast close animation. It can be: fadeOut, fadeOutUp, fadeOutDown, fadeOutLeft, fadeOutRight, flipOutX
     */
    'transitionOut' => 'fadeOut',

    /*
     * [string] - Transition In Mobile
     */
    'transitionInMobile' => 'fadeInUp',

    /*
     * [string] - Transition Out Mobile
     */
    'transitionOutMobile' => 'fadeOutDown',
];

由于 Flash 消息非常常见,我们提供了一个开箱即用的模板以供您开始使用。请将此模板放置在 body 标签的末尾之前。

    {{ noty_assets() }}
</body>

使用

在您的控制器中,在执行重定向之前,请调用 noty() 函数。

public function store()
{
    noty()->flash('Cool', 'Your data has been saved');

    return home();
}

您也可以这样做

noty()->flash('Hey!', 'This is message');
noty()->info('Hey!', 'This is message');
noty()->success('Hey!', 'This is message');
noty()->warning('Hey!', 'This is message');
noty()->danger('Hey!', 'This is message');

将此消息闪存到会话中后,您现在可以在您的视图(s)中显示它。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全

如果您发现任何与安全相关的问题,请通过电子邮件nico.audi@intidata.net联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅许可证文件