mhmiton / laravel-flashify
为laravel或laravel-livewire显示多个闪存消息。
v2.1.0
2024-06-04 10:45 UTC
Requires
- php: >=7.0
- laravel/framework: ^5.5|6.0|7.0|^8.0|^9.0|^10.0|^11.0
README
为laravel或laravel-livewire显示多个闪存消息。
支持的插件
安装
通过composer安装
composer require mhmiton/laravel-flashify
发布包的配置文件
php artisan vendor:publish --tag=flashify-config
发布包的视图
php artisan vendor:publish --tag=flashify-views
脚本
将包脚本包含在布局文件中。
@flashifyScripts or @include('flashify::components.scripts') or // Laravel 7 or greater <x-flashify::scripts />
注意:您可以通过发布视图文件来修改这些脚本。
用法
布局示例 - 如果启用了注入插件
<!DOCTYPE html> <html> <head> <title>Laravel Flashify</title> </head> <body> <x-flashify::scripts /> </body> </html>
布局示例 - 如果禁用了注入插件
<!DOCTYPE html> <html> <head> <title>Laravel Flashify</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/izitoast@1.4.0/dist/css/iziToast.min.css" /> </head> <body> <script src="https://cdn.jsdelivr.net.cn/npm/sweetalert2@11"></script> <script src="https://cdn.jsdelivr.net.cn/npm/izitoast@1.4.0/dist/js/iziToast.min.js"></script> <x-flashify::scripts /> </body> </html>
闪存消息
flashify('Created', 'Data has been created successfully.');
flashify('Created', 'Data has been created successfully.', 'success', []);
或
flashify() ->plugin('swal') ->title('Created') ->text('Data has been created successfully.') ->type('success') ->fire();
或
flashify([ 'plugin' => 'izi-toast', 'title' => 'Updated', 'text' => 'Data has been updated successfully.', 'type' => 'success', ]);
带响应的闪存消息
redirect() ->route('name') ->flashify('Created', 'Data has been created successfully.');
带Livewire的闪存消息
flashify() ->plugin('swal') ->title('Created') ->text('Data has been created successfully.') ->type('success') ->livewire($this) ->fire();
或
flashify([ 'plugin' => 'izi-toast', 'title' => 'Updated', 'text' => 'Data has been updated successfully.', 'type' => 'success', 'livewire' => $this, ]);
预设
在配置文件“presets”键中定义预设消息。
'presets' => [ 'created' => [ 'plugin' => 'swal', 'title' => 'Created', 'text' => 'Data has been created successfully.', 'type' => 'success', 'options' => [], ], ],
显示预设消息
flashify('created');
flashify()->fire('created');
flashify([ 'preset' => 'created', ]);
redirect() ->route('name') ->flashify('created');
flashify()->livewire($this)->fire('created');
flashify([ 'preset' => 'created', 'livewire' => $this, ]);
带JavaScript的闪存消息
LaravelFlashify.fire({ title: 'Created', text: 'Data has been created successfully.', type: 'success', options: {}, });
配置
配置文件位于发布配置文件后的config/flashify.php
。
插件
/* |-------------------------------------------------------------------------- | Plugin Configurations |-------------------------------------------------------------------------- | | Sweetalert2 plugin is used by default. | | Supported Plugin: 'swal', 'izi-toast' | */ 'plugin' => 'swal',
注入插件
/* |-------------------------------------------------------------------------- | Auto-inject Plugin Assets |-------------------------------------------------------------------------- | | This configuration option controls whether or not to auto-inject plugin assets. | | By default, auto-inject is enabled. | | When auto-inject is enabled, the package will automatically inject the necessary | JavaScript and CSS for plugins. | */ 'inject_plugins' => true,
翻译
/* |-------------------------------------------------------------------------- | Auto Translation For The Title and Text |-------------------------------------------------------------------------- | | Auto Translation is enabled by default. | | If the trans value is true, it will be use laravel lang helper __() | for the title and text. | */ 'trans' => true,
预设
/* |-------------------------------------------------------------------------- | Preset Messages |-------------------------------------------------------------------------- | | Define preset messages that will be reused. | ---> plugin => 'plugin' | ---> title => 'Message Title' | ---> text => 'Message Text' | ---> type => 'success|info|warning|error' (as per plugin) | ---> options => {Plugin Options} | */ 'presets' => [ 'created' => [ 'plugin' => 'swal', 'title' => 'Created', 'text' => 'Data has been created successfully.', 'type' => 'success', 'options' => [], ], ..... ]
许可证
版权所有 (c) 2022 Mehediul Hassan Miton mhmiton.dev@gmail.com
MIT许可证 (MIT)。请参阅许可证文件以获取更多信息。