Download the PHP package jantinnerezo/livewire-alert without Composer

On this page you can find all versions of the php package jantinnerezo/livewire-alert. 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 livewire-alert

Livewire Alert

Build Status PHPStan Analysis Total Downloads License

Livewire Alert is a Laravel Livewire package designed to integrate SweetAlert2 notifications seamlessly into Livewire projects. This package simplifies the process of displaying simple, customizable alerts to users, enhancing the interactivity and user experience of your Livewire projects.

You can check the interactive demo here: livewire-alert.laravel.cloud

Requirements

Installation

First, require the package with Composer:

Optionally, if you want to customize the global configuration, you can publish the config file:

Next, install SweetAlert2 via npm or yan:

NPM

Yarn

After installing SweetAlert2, import it into your resources/js/app.js file

If you prefer not to use package manager installation, you can include SweetAlert2 directly via CDN. Add the following script to your Blade layout file (e.g., resources/views/layouts/app.blade.php) before the closing </body> tag:

Filament

Integrate Livewire Alert in your Filament project, simply register the JavaScript asset in the boot method of your AppServiceProvider to import SweetAlert2.

Usage

This package provides a convenient Facade that allows you to trigger customizable SweetAlert2-based alerts in your Laravel Livewire application. The Facade uses a fluent interface, enabling you to chain methods to configure your alert before displaying it.

Basic Usage

Adding text

Available alert icons

Position

The position() method allows you to specify where the alert appears on the screen. You can use either the Position enum for type safety or a plain string for flexibility.

Using the Position Enum

Leverage the Position enum for predefined, type-safe options:

Using a String Value

Alternatively, you can pass a string directly, but it must exactly match one of the Position enum values, See: Position enum.

Toast Notification

Create a toast-style alert with the toast() method:

Timer

The timer() method sets an auto-dismiss timer for the alert, specifying how long (in milliseconds) the alert remains visible before closing automatically.

Usage

Pass an integer representing the duration in milliseconds:

Buttons

The LivewireAlert package provides methods to add and customize buttons in your alerts: withConfirmButton(), withCancelButton(), and withDenyButton(). Each button can trigger specific events, handled via onConfirm(), onDeny(), or onDismiss(), allowing you to execute custom logic in your Livewire component.

Confirm

Cancel

Deny

Button text

Alternatively, you can use confirmButtonText(), cancelButtonText(), and denyButtonText() to set the text after enabling the buttons with withConfirmButton(), withCancelButton(), or withDenyButton() without text:

Button Color

You can customize the appearance of buttons by setting their colors using the confirmButtonColor(), cancelButtonColor(), and denyButtonColor() methods. These methods accept a color value (e.g., color names, hex codes, or CSS-compatible strings) to style the respective buttons.

Button Events

Each button can trigger a corresponding event when clicked, allowing you to handle user interactions in your Livewire component.

onConfirm()

onDismiss()

onDeny()

Using them together example

Confirm Dialog

The asConfirm() method configures the alert as a confirmation dialog with a predefined options. It automatically applies a question icon, adds confirm and deny buttons with default text from the configuration, and disables the auto-dismiss timer, making it ideal for scenarios requiring explicit user input.

Handling Events

Combine with onConfirm() and onDeny() to handle user responses:

Inputs

The LivewireAlert package allows you to add input fields to alerts using the withOptions() method, leveraging SweetAlert2’s input capabilities. This is useful for collecting user input (e.g., text, selections) directly within the alert, with the input value returned via event handlers like onConfirm().

Usage

Use withOptions() to pass an array containing SweetAlert2 input options. Common input types include text, email, password, number, textarea, select, radio, checkbox, and file.

Add a simple text input:

Select Input Example

Handling Input Values

When an input is present, the $data parameter in event methods (e.g., onConfirm(), onDeny()) includes a value property containing the user’s input. This value depends on the input type:

Flash Alert

Need to flash alerts across requests? In this package you can leverage Laravel’s session flashing alerts and display them in your Livewire components. This feature, inspired by version 3’s simplicity, gives you full freedom to define your own session keys and structure, allowing tailored flash alerts that appear automatically (e.g., on mount()) after actions like redirects.

Options

The withOptions() method allows you to extend the alert’s configuration with any SweetAlert2-compatible options, giving you full control to customize its appearance, behavior, or functionality beyond the built-in methods. This is ideal for advanced use cases like adding inputs, modifying styles, or setting custom SweetAlert2 features.

For a comprehensive guide to customization and available configuration options, please refer to the SweetAlert2 documentation.

Dependency Injection

Who said you can only use the Facade? With this package, you can also inject the Jantinnerezo\LivewireAlert\LivewireAlert class directly into your Livewire component methods via dependency injection. This approach lets you access the alert functionality within the context of your component, offering a clean alternative to the Facade syntax.

All methods remain available, and you can chain them fluently just like with the Facade!

Looking for v3?

If you’re seeking documentation for livewire-alert v3, note that the last release of the version 3 series was v3.0.3, available on GitHub at v3.0.3 Released on March 11, 2024, this version supports Livewire 3 and latest Laravel 12 and includes features like basic alert functionality with the LivewireAlert trait.

This release, however, is a major refactor of the package, introducing a new architecture and enhanced features (like the fluent Facade interface and dependency injection). As a result, the documentation below focuses on v4.

For v3-specific usage:

For ongoing projects, I recommend upgrading to v4.0 to take advantage of the improved API and feature set detailed in this documentation.

Testing

Contributors

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


All versions of livewire-alert with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
livewire/livewire Version ^3.0
illuminate/support Version ^10.0|^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 jantinnerezo/livewire-alert contains the following files

Loading the files please wait ....