uyanik13/sweet-alert

A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL BY Ogur Uyanik

dev-master 2023-12-11 10:02 UTC

This package is auto-updated.

Last update: 2023-12-11 10:03:27 UTC


README

LARAVEL 6-7-8 Sweet Alert | ALSO FIXED LIVEWIRE INTEGRATION

68747470733a2f2f7261772e6769746875622e636f6d2f7377656574616c657274322f7377656574616c657274322f6d61737465722f6173736574732f7377656574616c657274322e676966

Install

To get started with SweetAlert2, use Composer to add the package to your project's dependencies:

composer require uyanik13/sweet-alert

Add This Provider to app.php

DRO\SweetAlert\SweetAlertServiceProvider::class,

'providers' => [
    /*
    * Package Service Providers...
    */
    DRO\SweetAlert\SweetAlertServiceProvider::class,
],

Also, add the Alert facade to the aliases array in your app configuration file:

'Alert' => DRO\SweetAlert\Facades\Alert::class,

Include 'sweetalert::alert' in master layout

@include('sweetalert::alert')

and run the below command to publish the package assets.

php artisan sweetalert:publish

Using the Middleware

\DRO\SweetAlert\ToSweetAlert::class,

ENV file

SWEET_ALERT_MIDDLEWARE_AUTO_CLOSE=false
SWEET_ALERT_MIDDLEWARE_TOAST_POSITION='top-end'
SWEET_ALERT_MIDDLEWARE_TOAST_CLOSE_BUTTON=true
SWEET_ALERT_MIDDLEWARE_ALERT_CLOSE_TIME=5000
SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES=true

Examples

public function store(Request $request)
{
    //validation
    $request->validate([
        'title' => 'required|min:3',
        'body' => 'required|min:3'
    ]);
    $task = Task::create($request->all());
    return redirect('tasks')->with('success', 'Task Created Successfully!');
    // OR
    return redirect('tasks')->withSuccess('Task Created Successfully!');
}

Livewire Usage

public function submit()
{
	$this->alert('success', 'Submission successful!');
}

// Success event
$this->alert('success', 'Submission successful!');

// Information event
$this->alert('info', 'Hello, Awesome Developer!');

// Warning event
$this->alert('warning', 'You have been warned!');

// Error event
$this->alert('error', 'Whoops! you did it again!');


// Success event
$this->alert('success', 'You are successful!', [
	'position'  =>  'center',
	'timer'  =>  15000,
	'toast'  =>  false,
	'text'  =>  'I am a subtext',
	'showCancelButton'  =>  false,
	'showConfirmButton'  =>  false
]);

SweetAlert2 is open-sourced software licensed under the MIT License (MIT). Please see License File for more information.

Made ❤️ with Laravel