Download the PHP package sweetalert2/laravel without Composer

On this page you can find all versions of the php package sweetalert2/laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel

Installation

Include the SweetAlert2 template in your layout file (usually resources/views/layouts/app.blade.php):

Usage

Laravel Controllers, Middleware, Views etc.

You can now call Swal::fire() or any of the available helper methods anywhere in your Laravel application (controllers, middleware, etc.) to show a SweetAlert2 alert:

The full list of options can be found in the SweetAlert2 documentation.

Helpers

Available Laravel helper methods:

Livewire Components

You can now call $this->swalFire or any of the available helper methods in your Livewire component to show realtime popups and toasts:

LivewireExample.php

The full list of options can be found in the SweetAlert2 documentation.

livewire-example.blade.php

Helpers

Available Livewire helper methods:

FAQ

1. How is this different to the realrashid/sweet-alert package?

The realrashid/sweet-alert package is too opinionated and too complex: facade, midddleware, adding vendor files, whatnot 🤯. And all that with 0 tests.

This package is simple, straightforward, and unopinionated. Its API is aimed to be as close as possible to the original sweetalert2.

It simply provides a way to use SweetAlert2 in your Laravel or Livewire application without touching JS or CSS files.

2. How does it work?

Depending on whether you use the Swal class or the WithSweetAlert trait, within either a Laravel only or Livewire context, the behaviour is slightly different.

Laravel controllers, middleware, views etc

  1. The Swal::fire() or $this->swalFire() method will pass the options to the flashed session.
  2. The blade partial template will check if there is any flashed session data and will render the SweetAlert2 popup.

Livewire components

Realtime

  1. The $this->swalFire() method will dispatch a Livewire event with the options to the browser window within the current request.
  2. The blade partial template will listen for the Livewire event and will render the SweetAlert2 popup.

This works on the first request and subsequent Livewire update requests.

First request or after redirect

  1. The Swal::fire() method will pass the options to the flashed session.
  2. The blade partial template will show a popup on the first request.

This works only on the first request, not on Livewire update requests.

This is ideal for showing messages after redirecting the user from a Livewire component, for example if they lack permissions to view a page:

3. How is the SweetAlert2 JavaScript library loaded?

This package uses a smart loading strategy for the SweetAlert2 library:

  1. Check for existing SweetAlert2: If window.Swal is already available, it will use the existing import.

  2. Dynamic CDN loading: If SweetAlert2 is not loaded, it will dynamically import it from the official CDN (https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.esm.all.min.js).

4. What are the limitations?

SweetAlert2 is a JavaScript package and some of its options are JS callbacks. It's not possible to use them in the Swal::fire() or $this->swalFire() methods. If you need to use JS callbacks, you have to go to JS and use the SweetAlert2 API directly.


All versions of laravel with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^11.0 || ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sweetalert2/laravel contains the following files

Loading the files please wait ....