PHP code example of uxweb / sweet-alert
1. Go to this page and download the library: Download uxweb/sweet-alert library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
uxweb / sweet-alert example snippets
'providers' => [
UxWeb\SweetAlert\SweetAlertServiceProvider::class,
];
'aliases' => [
'Alert' => UxWeb\SweetAlert\SweetAlert::class,
];
use SweetAlert;
public function store()
{
SweetAlert::message('Robots are working!');
return Redirect::home();
}
SweetAlert::message('Message', 'Optional Title');
SweetAlert::basic('Basic Message', 'Mandatory Title');
SweetAlert::info('Info Message', 'Optional Title');
SweetAlert::success('Success Message', 'Optional Title');
SweetAlert::error('Error Message', 'Optional Title');
SweetAlert::warning('Warning Message', 'Optional Title');
alert()->message('Message', 'Optional Title');
alert()->basic('Basic Message', 'Mandatory Title');
alert()->info('Info Message', 'Optional Title');
alert()->success('Success Message', 'Optional Title');
alert()->error('Error Message', 'Optional Title');
alert()->warning('Warning Message', 'Optional Title');
alert()->basic('Basic Message', 'Mandatory Title')->autoclose(3500);
alert()->error('Error Message', 'Optional Title')->persistent('Close');
/**
* Destroy the user's session (logout).
*
* @return Response
*/
public function destroy()
{
Auth::logout();
alert()->success('You have been logged out.', 'Good bye!');
return home();
}
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
...
\UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
],
'api' => [
'throttle:60,1',
],
];
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
....
'sweetalert' => \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
];
return redirect('dashboard')->with('success', 'Profile updated!');
return redirect()->back()->with('error', 'Profile updated!');
// -> Remember!, the number is set in milliseconds
alert('Hello World!')->autoclose(3000);
// -> The text will appear in the button
alert('Hello World!')->persistent("Close this");
// -> html will be evaluated
alert('<a href="#">Click me</a>')->html()->persistent("No, thanks");
Session::get('sweet_alert.text')
Session::get('sweet_alert.title')
Session::get('sweet_alert.icon')
Session::get('sweet_alert.closeOnClickOutside')
Session::get('sweet_alert.buttons')
Session::get('sweet_alert.timer')
SweetAlert::message('Welcome back!');
return Redirect::home();
SweetAlert::message('Your profile is up to date', 'Wonderful!');
return Redirect::home();
SweetAlert::message('Thanks for comment!')->persistent('Close');
return Redirect::home();
SweetAlert::info('Email was sent!');
return Redirect::home();
SweetAlert::error('Something went wrong', 'Oops!');
return Redirect::home();
SweetAlert::success('Good job!');
return Redirect::home();
SweetAlert::info('Random lorempixel.com : <img src="http://lorempixel.com/150/150/">')->html();
return Redirect::home();
SweetAlert::success('Good job!')->persistent("Close");
return Redirect::home();
bash
php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=config
bash
php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=views
html
@if (Session::has('sweet_alert.alert'))
<script>
swal({
text: "{!! Session::get('sweet_alert.text') !!}",
title: "{!! Session::get('sweet_alert.title') !!}",
timer: {!! Session::get('sweet_alert.timer') !!},
icon: "{!! Session::get('sweet_alert.type') !!}",
buttons: "{!! Session::get('sweet_alert.buttons') !!}",
// more options
});
</script>
@endif