Add beautiful alerts by SweetAlert directly into your Laravel
application, with a simple setup, and handly helpers.
View Demo
ยท
Report Bug
ยท
Request Feature
Sweetalert is a package for Laravel that allows you to directly interact with SweetAlert. Initially created by uxweb, but now maintained and added support for the latest release of SweetAlert.
We will be releasing some custom alerts within this package in the future, and will continue to maintain the package for future releases of SweetAlert2.
wavey/sweetalert
is really simple to set up, If you are familiar with Composer & Laravel, you will most likely know
what to do already, however, follow the guide below to get the alerts working and help you make your application look
stunning.
Firstly, require the package into your application through composer using the following command:
composer require wavey/sweetalert
Once you have completed this, run the installer:
php artisan sweetalert:install
This will publish the sweetalert.blade.php
file into resources/views/vendor/wavey/sweetalert
.
You will now need to require the SweetAlert2 package. The simplest way to achieve this is to include the CDN link, simply add the following link into your layouts.
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
Once you have done this, you will need to include the blade file into your layouts, Inside your layout, add:
@include('sweetalert::sweetalert')
Now, you are good to go! Check out the uage section to learn how to show alerts from your controllers.
if you don't want to use the CDN link, you can also include the SweetAlert2 library through NPM.
If you want to install from your command line, run the following command:
npm install sweetalert2
Then you need to include the library into your javascript, do the following:
// ES6 Modules or TypeScript
import Swal from 'sweetalert2'
// CommonJS
const Swal = require('sweetalert2')
Now compile your assets and include your main javascript file into your views, and you are good to go!
You can also install the NPM package through our install command. When installing the package, run the following command instead:
php artisan sweetalert:install --npm
This command will install the NPM package and include inside resources/js/app.js
and then run npm run dev
to compile
your assets.
We have made Sweetalert very simple to use, firstly, include the library at the top of your controller:
use Wavey\Sweetalert\Sweetalert;
Then, simply call the method you want, below is the methods we support currently:
Sweetalert::basic('Description', 'Title');
Sweetalert::info('Description', 'Title');
Sweetalert::success('Description', 'Title');
Sweetalert::error('Description', 'Title');
Sweetalert::warning('Description', 'Title');
Sweetalert::message('Description', 'Title');
Sweetalert::message('Description <h2>Custom HTML</h2>', 'Title')->html();
We will be releasing support for Toast notifications too, along with some custom alert helpers in the coming releases.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Your Name - @waveygroup - [email protected]
Project Link: https://github.com/waveygroup/sweetalert