Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sweet Alert Laravel Package

realrashid/sweet-alert

Laravel package to integrate SweetAlert2 popups: stylish alerts, confirmations, toasts, and notifications. Trigger from controllers or views with simple helpers and session flashes, customize options, and improve UX with minimal setup.

View on GitHub
Deep Wiki
Context7

Confirm Alert

Description

This function shows a confirmation alert before deleting data. It accepts two parameters: $title and $text. When called, it will set the configuration options for the confirmation popup and store them in a session flash data.

Parameters

$title This parameter sets the title of the confirmation popup. It is a required parameter.

$text This parameter sets the text of the confirmation popup. It is a optional parameter.

Usage

To use the confirmDelete function, you need to call it in your controller method in my case its index , passing in the required parameters. For example:

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index()
    {
        $users = User::latest()->paginate(10);

        $title = 'Delete User!';
        $text = "Are you sure you want to delete?";
        confirmDelete($title, $text);
        return view('users.index', compact('users'));
    }
}

This allows the confirmation alert to be displayed after a clicking the delete button.

In your view, you can add the data-confirm-delete attribute to the delete button to trigger the confirmation popup. The confirmation popup will use the configuration options set in the session flash data. For example:

<a href="{{ route('users.destroy', $user->id) }}" class="btn btn-danger" data-confirm-delete="true">Delete</a>

When the delete button is clicked, the confirmation popup will be displayed. If the user confirms the delete action, the delete request will be sent to the users/destroy route. If the user cancels the delete action, the confirmation popup will be closed and nothing will happen.

Environment Variables

The following environment variables can be used to customize the confirm alert:

SWEET_ALERT_CONFIRM_DELETE_CONFIRM_BUTTON_TEXT This variable sets the text of the confirmation button. Default is Yes, delete it!.

SWEET_ALERT_CONFIRM_DELETE_CANCEL_BUTTON_TEXT This variable sets the text of the cancel button. Default is Cancel.

SWEET_ALERT_CONFIRM_DELETE_SHOW_CANCEL_BUTTON This variable sets whether to show the cancel button in the popup. Possible values are true or false. Default is true.

SWEET_ALERT_CONFIRM_DELETE_SHOW_CLOSE_BUTTON This variable sets whether to show the close button in the popup. Possible values are true or false. Default is false.

SWEET_ALERT_CONFIRM_DELETE_ICON This variable sets icon of the popup. Default is warning.

SWEET_ALERT_CONFIRM_DELETE_SHOW_LOADER_ON_CONFIRM This variable sets whether to show a loader in delete button of the popup. Possible values are true or false. Default is true.

You can customize the configuration options of the confirmation popup by setting the environment variables in your .env file. For example:

SWEET_ALERT_CONFIRM_DELETE_CONFIRM_BUTTON_TEXT='Yes, delete it!'
SWEET_ALERT_CONFIRM_DELETE_CANCEL_BUTTON_TEXT='No, cancel'
SWEET_ALERT_CONFIRM_DELETE_SHOW_CANCEL_BUTTON=true
SWEET_ALERT_CONFIRM_DELETE_SHOW_CLOSE_BUTTON=false
SWEET_ALERT_CONFIRM_DELETE_ICON='warning'
SWEET_ALERT_CONFIRM_DELETE_SHOW_LOADER_ON_CONFIRM=true

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4