buivanhuy/sweetalert-laravel
最新稳定版本:v1.2.1
Composer 安装命令:
composer require buivanhuy/sweetalert-laravel
包简介
SweetAlert2 integration for Laravel (supports Livewire, Blade)
README 文档
README
SweetAlert Laravel is a simple integration package that brings SweetAlert2 into your Laravel application with minimal setup. This package allows you to easily use Sweetalert from both Blade and Livewire, without the need to manually install SweetAlert2 via npm or configure imports.
Installation
To install the SweetAlert Laravel package, you can use Composer. Run the following command in your terminal at the root of your Laravel project:
composer require buivanhuy/sweetalert-laravel php artisan vendor:publish --tag=public
Note
This will publish the SweetAlert2 assets to your public/vendor/sweetalert2 directory.
Include swal:index your layout file
@include('swal::index')
Example layout file
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> @include('swal::index') <title>Web title</title> </head> <body> </body> </html>
Usage
Displaying via session
In your controller:
// Using the Swal facade use SweetAlert\Swal; Swal::fire([ 'icon' => 'success', 'title' => 'Success!', 'text' => 'Your action was successful.', ]); // Or return redirect()->back()->with('swal', [ 'icon' => 'success', 'title' => 'Success!', 'text' => 'Your action was successful.', ]);
Displaying via Livewire
In your Livewire component:
public function someAction() { $this->dispatch('swal', [ 'icon' => 'success', 'title' => 'Success!', 'text' => 'Your action was successful.', ]); }
The full list of options can be found in the SweetAlert2 documentation.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-02