airoinfo / laravel-alert
一个简单的PHP包,用于在Laravel框架和Vue中显示警告
2.0.2
2020-11-27 05:34 UTC
Requires
- php: ^5.6|^7.0|^8.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0
README
此包基于Laravel框架、Vue和Element UI,也可选支持vue-notification,易于创建出色的通知视图和Laravel Facade以在后台调用
安装
重要 确保您的larval项目的Vue和Element UI运行正常。
使用composer安装包
$ composer require airoinfo/laravel-alert
注意 如果您的Laravel版本高于5.6,则包将自动注册ServiceProvider到app.php。但如果您的版本高于5.6,您必须自行注册。
config/app.php
'provider' => [ // package ServiceProvider Airo\Alert\AlertServiceProvider::class, ]
'alias' => [ 'Alert' => Airo\Alert\AlertFacade::class, ]
设置
1. 发布供应商
在此包中,我们已经提供了blade和Vue组件。您可以使用默认设置,也可以创建自己的来捕获消息
发布视图Blade到resource\vendor\notify
$ php artisan vendor:publish --tag=views --force
发布Vue组件到resource\js\components
$ php artisan vendor:publish —-tag=components --force
2. 注册您的Vue组件
例如 resource\js\app.js
Vue.component('notify-component', require('./components/NotifyComponent.vue'));
3. 将notify blade包含到您的布局中
例如 views\layouts\app.blade.php
@include('alert::notify')
4. 在控制器中使用它
use Airo\Alert\AlertFacade; class HomeController { public function login() { //when Login success Alert::success(['message1', 'message2', '...']); //when login fail Alert::errors(['message1', 'message2', '...']); } }