odannyc / laravel-alertify
此包最新版本(1.0.0)没有可用的许可信息。
Laravel 的 alertify 包
1.0.0
2017-07-17 20:37 UTC
Requires
- illuminate/session: ^5.4
- illuminate/support: ^5.4
This package is auto-updated.
Last update: 2024-09-14 09:32:48 UTC
README
使用 alertify 的 Laravel 警报库
alertify()->success("The laravel-alertify package is awesome!");
安装
此包使用 composer,因此可以这样要求:
composer require odannyc/laravel-alertify
您还需要拉取 alertify.js
项目。该项目位于此处: https://alertifyjs.org/
您可以使用 NPM
npm install --save alertify.js
或者在您的 app.blade.php
模板中包含它的 CDN 版本。(文件可能因您的 Laravel 安装而异)
<script src="https://cdn.rawgit.com/alertifyjs/alertify.js/v1.0.10/dist/js/alertify.js"></script>
在 config/app.php
中包含服务提供者
'providers' => [ odannyc\Alertify\AlertifyServiceProvider::class, ];
此外,在 config/app.php
中包含别名
'aliases' => [ 'Alertify' => odannyc\Alertify\Alertify::class, ];
然后,在您的 Laravel 安装模板中,在 HTML 的任何位置包含视图
@include('alertify::alertify')
用法
确保在使用此包之前包含 alertify.js
。(见上述安装说明)
您可以在返回/重定向到视图之前调用 alertify()
辅助函数
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function update(Request $request) { alertify()->success('Updated record successfully'); // You can also add multiple alerts! alertify('You are awesome!'); return redirect()->back(); }
您可以使用 alertify()
辅助函数或使用静态 Facade
Alertify::standard('I like alerts')
有 3 种类型的警报
alertify('this is a standard alert (shows black)'); alertify()->success('this is a success alert (shows green)'); alertify()->error('this is an error alert (shows red)');
您也可以通过多次调用该函数来显示多个警报
alertify('alert 1'); alertify('alert 2');
您可以根据逻辑保存警报并编辑它
$alert = alertify('i am an alert'); if ($error) { $alert->error(); } else { $alert->success(); }
每个警报都可以添加许多选项
// Show the alert for 5000 milliseconds and then dismisses itself (default: 4000) alertify('delayed 5 seconds')->delay(5000); // Alert stays displayed with no timeout alertify('i stay displayed on the screen')->persistent(); // Alert can be clicked to be dismissed alertify('i can be clicked to be dismissed')->clickToClose(); // You can position alerts (default: 'top right') alertify('i am on the bottom left')->position('bottom left'); // You can attach the alert to some other HTML element (default: 'document.body') alertify('i am displayed on a different parent')->attach('.some-html-accessor')
您也可以链式添加选项
alertify()->success('i am daisychained')->delay(10000)->clickToClose()->position('bottom right');