Giter Club home page Giter Club logo

sweet-alert's Introduction

Easy Sweet Alert Messages for Laravel

A success alert

Latest Version StyleCI Total Downloads

Installation

Require the package using Composer.

composer require uxweb/sweet-alert

If using laravel < 5.5 include the service provider and alias within config/app.php.

'providers' => [
    UxWeb\SweetAlert\SweetAlertServiceProvider::class,
];

'aliases' => [
    'Alert' => UxWeb\SweetAlert\SweetAlert::class,
];

Installing Frontend Dependency

This package works only by using the BEAUTIFUL REPLACEMENT FOR JAVASCRIPT'S "ALERT".

Using a CDN

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Include this in your blade layout -->
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  </head>
  <body>
    @include('sweet::alert')
  </body>
</html>

Using Laravel Mix

Install using Yarn

yarn add sweetalert --dev

Install using NPM

npm install sweetalert --save-dev

Require sweetalert within your resources/js/bootstrap.js file.

// ...

require("sweetalert");

// ...

Then make sure to include your scripts in your blade layout. Remove the defer attribute if your script tag contains it, defer will delay the execution of the script which will cause an error as the sweet::alert blade template is rendered first by the browser as html.

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>
  </head>
  <body>
    @include('sweet::alert')
  </body>
</html>

Finally compile your assets with Mix

npm run dev

Usage

Using the Facade

First import the SweetAlert facade in your controller.

use SweetAlert;

Within your controllers, before you perform a redirect...

public function store()
{
    SweetAlert::message('Robots are working!');

    return Redirect::home();
}

Here are some examples on how you can use the facade:

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');

Using the helper function

alert($message = null, $title = '')

In addition to the previous listed methods you can also just use the helper function without specifying any message type. Doing so is similar to:

alert()->message('Message', 'Optional Title')

Like with the Facade we can use the helper with the same methods:

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');

Within your controllers, before you perform a redirect...

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    alert()->success('You have been logged out.', 'Good bye!');

    return home();
}

For a general information alert, just do: alert('Some message'); (same as alert()->message('Some message');).

Using the Middleware

Middleware Groups

First register the middleware in web middleware groups by simply adding the middleware class UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class into the $middlewareGroups of your app/Http/Kernel.php class:

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        ...
        \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
    ],

    'api' => [
        'throttle:60,1',
    ],
];

Make sure you register the middleware within the 'web' group only.

Route Middleware

Or if you would like to assign the middleware to specific routes only, you should add the middleware to $routeMiddleware in app/Http/Kernel.php file:

protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    ....
    'sweetalert' => \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
];

Next step: within your controllers, set your return message (using with()) and send the proper message and proper type.

return redirect('dashboard')->with('success', 'Profile updated!');

or

return redirect()->back()->with('error', 'Profile updated!');

NOTE: When using the middleware it will make an alert to display if it detects any of the following keys flashed into the session: error, success, warning, info, message, basic.

Final Considerations

By default, all alerts will dismiss after a sensible default number of seconds.

But not to worry, if you need to specify a different time you can:

// -> Remember!, the number is set in milliseconds
alert('Hello World!')->autoclose(3000);

Also, if you need the alert to be persistent on the page until the user dismiss it by pressing the alert confirmation button:

// -> The text will appear in the button
alert('Hello World!')->persistent("Close this");

You can render html in your message with the html() method like this:

// -> html will be evaluated
alert('<a href="#">Click me</a>')->html()->persistent("No, thanks");

Customize

Config

If you need to customize the default configuration options for this package just export the configuration file:

php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=config

A sweet-alert.php configuration file will be published to your config directory. By now, the only configuration that can be changed is the timer for all autoclose alerts.

View

If you need to customize the included alert message view, run:

php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=views

The package view is located in the resources/views/vendor/sweet/ directory.

You can customize this view to fit your needs.

Configuration Options

You have access to the following configuration options to build a custom view:

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')

Please check the CONFIGURATION section in the website for all other options available.

Default View

The sweet_alert.alert session key contains a JSON configuration object to pass it directly to Sweet Alert.

@if (Session::has('sweet_alert.alert'))
<script>
  swal({!! Session::get('sweet_alert.alert') !!});
</script>
@endif

Note that {!! !!} are used to output the json configuration object unescaped, it will not work with {{ }} escaped output tags.

Custom View

This is an example of how you can customize your view to fit your needs:

@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

Note that you must use "" (double quotes) to wrap the values except for the timer option.

Tests

To run the included test suite:

vendor/bin/phpunit

Demo

SweetAlert::message('Welcome back!');

return Redirect::home();

A simple alert

SweetAlert::message('Your profile is up to date', 'Wonderful!');

return Redirect::home();

A simple alert with title

SweetAlert::message('Thanks for comment!')->persistent('Close');

return Redirect::home();

A simple alert with title and button

SweetAlert::info('Email was sent!');

return Redirect::home();

A info alert

SweetAlert::error('Something went wrong', 'Oops!');

return Redirect::home();

A error alert

SweetAlert::success('Good job!');

return Redirect::home();

A success alert

SweetAlert::info('Random lorempixel.com : <img src="http://lorempixel.com/150/150/">')->html();

return Redirect::home();

HTML in message

SweetAlert::success('Good job!')->persistent("Close");

return Redirect::home();

A persistent alert

License

Sweet Alert for Laravel is open-sourced software licensed under the MIT license.

sweet-alert's People

Contributors

al0mie avatar backstageel avatar blpraveen avatar bumbummen99 avatar davidcb avatar djsigfried56 avatar georgeboot avatar hanetooth avatar joeriaben avatar jrean avatar julientant avatar khaledsmq avatar lasseeee avatar lespilettemaxime avatar meijdenmedia avatar mmonbr avatar nelson6e65 avatar ronydebnath avatar ssfinney avatar thewebartisan7 avatar tomopongrac avatar tortlewortle avatar uxweb avatar uziel-bueno avatar vrajroham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sweet-alert's Issues

icon

Hi ,
Im having some issue when using Alert::success('Success Message', 'Optional Title'); on my controller , its not showing any icons just the text. i do have the css and js file on my directory. how can i fix this ?

works from routes but not controllers?

I cant quite figure out why Alert will only work when I test it in Routes.

but when I implement in my controllers I get no response...no error messages.
Is there something I should be aware of that may "unset" the alert session when it redirects between controllers?
would appreciate some insignt

Call action from Controller after Confirm in alert

Hi,
First, great component! :)

In your custom view ("uxweb/sweet-alert": "~1.1"):

  @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') !!},
        type: "{!! Session::get('sweet_alert.type') !!}",
        showConfirmButton: "{!! Session::get('sweet_alert.showConfirmButton') !!}",
        confirmButtonText: "Da, vrea sa dezactivez!",
        confirmButtonColor: "{!! Session::get('sweet_alert.confirmButtonColor') !!}",
        showCancelButton: "{!! Session::get('sweet_alert.showCancelButton') !!}",
        confirmCancelText: "{!! Session::get('sweet_alert.confirmCancelText') !!}",
        closeOnConfirm: false,
        closeOnCancel: false
        // more options
      })
</script>
   @endif

I want to implement (after // more options):

   ....
   // more options
   closeOnConfirm: false,
   closeOnCancel: false
 },
 function(isConfirm){
   if (isConfirm) {
    swal("Deleted!", "Your imaginary file has been deleted.", "success");
    } else {
   swal("Cancelled", "Your imaginary file is safe :)", "error");
    }
 });

How can I call an action from Controller after isConfirm?

type -> icon

According to their documentation seems like that kay might change?

Must always sepecify null in autoclose to have persitnet work?

Hi,

I seem to require entering a persistent window like this:
alert()->warning(trans('surveys.noresponses'), $results['status'])->persistent("OK")->autoclose(null)

Just entering

alert()->warning(trans('surveys.noresponses'),$results['status'])->persistent("OK")

without a autoclose causes the window to close as soon as it displays even with Persistent on.

Thanks

Gary

Missing persistent button when using html in the message (simple fix)

If you want to use html in combination with a persistent button, you have to adjust the lines 264 and 265 in SweetAlertNotifier.php. This is because the options 'showConfirmButton' & 'confirmButtonTex' are deprecated.

Example:

Alert::error('<p>Text</p>', 'Oops!')->html()->persistent('ButtonText');

Adjust the lines 264 and 265 in SweetAlertNotifier.php;

from

$this->config['showConfirmButton'] = true;
$this->config['confirmButtonText'] = $buttonText;

to

$this->config['buttons'] = true;
$this->config['buttons'] = $buttonText;

Readme.md - typo's?

on the readme in 3 different places it says sweatalert instead of sweetalert. i assume this is a typo and probably caused many people's issue when they copy and paste. do a find on webpage of sweat to see what i mean. thanks.

screen shot 2017-03-18 at 8 43 45 pm

Confirm Button in Controller

Is there some way for put a Confirm message in a Controller in Laravel?

I only have the possibility to print

Alert::warning('Are you sure?', 'message')->persistent('Close');

How Can I do it like a confirm button like views?

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') !!}, type: "{!! Session::get('sweet_alert.type') !!}", showConfirmButton: "{!! Session::get('sweet_alert.showConfirmButton') !!}", confirmButtonText: "{!! Session::get('sweet_alert.confirmButtonText') !!}", confirmButtonColor: "#AEDEF4" }); </script> endif

Class 'Alert' not found in Laravel 5.3.28

Hello,
I use Laravel 5.3.28 and I install package form composer require uxweb/sweet-alert
and follow the instruction here. this is my config/app.php and my controller SentinelRegisterController.php

On browsers I got this error FatalThrowableError in SentinelRegisterController.php line 17: Class 'Alert' not found

And i see in my PhpStorm i see notice
screen shot 2017-01-03 at 10 54 40 pm

With helper function alert()->success('You have been logged out.', 'Good bye!');
I got ReflectionException in Container.php line 749: Class uxweb.sweet-alert does not exist

In view i put @include('sweet::alert') after {!! Html::style('assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css') !!} {!! Html::script('assets/global/plugins/bootstrap-sweetalert/sweetalert.min.js') !!} in layout.blade.php

what i mistake? Please help me.
Best Regard.

Not showing messages from Named Error Bags

Hello, for some reason I had problems showing messages from Named Error Bags.

Something like:

return redirect('register')
    ->withErrors($validator, 'login');

To access the named ErrorBag it's necessary to do:

{{ $errors->login->first('email') }}

so, I had to add the following code to the ConvertMessagesToSweetAlert.php middleware:

public function handle($request, Closure $next)
{
     ...

     if ($request->session()->has('errors')) {
            $message = $request->session()->get('errors');
                       
             /* Added new condition */
	     if (!$message->hasBag('default')) {
	       $bagName = array_keys($message->getBags())[0];
	       $message = $message->$bagName;
	      }
	     /* End new condition */

            if (!is_string($message)) {
                $message = $this->prepareErrors($message->getMessages());
            }

            alert()->error($message)->html()->persistent();
        }

        return $next($request);
}

It should be improved, but for the moment hope it works for something.
Was there another way to solve it? Thank you.

Is this updated to v. 2?

Hi, i was using this packaged and decided to upgrade Sweet Alert from v.1 to v.2.

But the docs for this package still asks for a css file (that is no longer required). I am also getting "deprecated" messages in my console.

Is this package ready for v. 2 of SweetAlert?

Unable to use Alert

Dear Developers,

I try to test out the sweetalert however it doesn't work. Some issues popped up as follows:

route.php
`use Alert;

Route::get('test', function(){
Alert::message('testing');
});`

when I type use Alert like this it pops that

ErrorException in routes.php line 3:
The use statement with non-compound name 'Alert' has no effect

I am not sure if this is a sign where I install it improperly or what. But when I delete use Alert; then refresh the localhost:8000/test page, it is just white plain.

I did put

<script src="{{ url('js/sweetalert.min.js') }}"></script>


 <link rel="stylesheet" type="text/css" href="{{ url('css/sweetalert.css') }}">

and both are placed in the right files. Please help!

Facade Alert not found

On Laravel 5.2
First, I installed sweet-alert via composer and add line to providers and aliases in config/app.php
And, I do this in my controller :
public function update($id, Request $request) { $place = Place::findOrfail($id); $place->update($request->all()); $place->activities()->sync($request->get('activities')); // \Session::flash('flash_message', 'success !'); Alert::message('success !'); return redirect(route('places.edit', $id)); }

And i have this result :
FatalErrorException in PlacesController.php line 61: Class 'App\Http\Controllers\Alert' not found

Can you help me please ?

Thx, Fred

Typos in readme

There is a typo in the middleware section \UxWeb\SweetAlert\ConvertMessagesIntoSwetAlert::class,. It should read \UxWeb\SweetAlert\ConvertMessagesIntoSweatAlert::class,

update please:,D

bro you could update the package to the new version of sweet alert, the problem about the alerts I can correct for now, if you want I sent the code to change. but please upgrade it ;(

Way to deal with sweetalert2s autoclose promise rejection

sweetalert2, a more accessible drop in replacement has a promise that gets resolved or rejected on autoclose. Everything works, but it makes for an annoying console.log message. Do not mind adding this myself, cannot seem to find where your building the actual JS call however

where and how do you set the configuration options?

For example:

Session::get('sweet_alert.confirmButtonText')

Where do I set this?

I have done:

Alert::success('Success Message', 'Optional Title')->persistent('Close');

Do I just chain?

Alert::success('Success Message', 'Optional Title')->confirmButtonText('Close');

Does this work on Laravel 5.3.10

Good Day,

I would like to ask if this version "uxweb/sweet-alert": "dev-master" works on Laravel 5.3.10?

I follow the instruction here. However, the alert doesn't show up in my controller store method, just what is showed in documentation.
public function store(CreateTestScaffoldRequest $request)
{
$input = $request->all();

    $testScaffold = $this->testScaffoldRepository->create($input);

    Alert::message('Robots are working!');
    return redirect(route('testScaffolds.index'));

}

@ my index.blade.php I also @include('sweet::alert')
On browsers console I got this error: Uncaught ReferenceError: swal is not defined
(anonymous function) @ testScaffolds:94

That points to this html script line of codes:
swal({"showConfirmButton":false,"allowOutsideClick":true,"timer":1800,"title":"Robots are working!"});

SA position

Would love to have the ability to define position from the function call in a controller.

Where is sweetalert.css ?

I followed all installation instructions and there is no sweetalert.css in my project folder at all, checked node_modules as well.

Custom View

Hi,

First let me say congratulation for that package! Well done!!

I published the vendor view and I try to simply override the confirmButtonColor option.
So by default your view is as following:

@if (Session::has('sweet_alert.alert'))
    <script>
        swal(
            {!! Session::get('sweet_alert.alert') !!}
        );
    </script>
@endif

I tried several time but...

@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') !!},
            type: '{!! Session::get('sweet_alert.type') !!}'
            // more options
        });
    </script>
@endif

The problem is I loose the context ->persistent() or ->autoclose() for showConfirmButton, it displays the button when it should not because I can't properly set the option...

It's like I'm missing a {!! Session::get('sweet_alert.showConfirmButton') !!} to dynamically get the boolean :)

I'm probably missing something but, could you please be kind and provide me a sample code exemple on how you would simply keep your perfect work but customise the confirmButtonColor?

Regards,

:)

Nothing happened

I just did as it is on documentation:

composer require uxweb/sweet-alert

'providers' => [
UxWeb\SweetAlert\SweetAlertServiceProvider::class,
];

'aliases' => [
'Alert' => UxWeb\SweetAlert\SweetAlert::class,
];

npm install sweetalert

in controller imported
use Alert;

in function
Alert::message('Robots are working!');

in layout included

<script src="js/sweetalert.min.js"></script>

@include('sweet::alert')

After that nothing happened.

Did I miss something?

send customize parameters from Laravel controller

Hi,
First, great component! :)

I'm using your custom view ("uxweb/sweet-alert": "~1.1"):

 @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') !!},
        type: "{!! Session::get('sweet_alert.type') !!}",
        showConfirmButton: "{!! Session::get('sweet_alert.showConfirmButton') !!}",
        confirmButtonText: "{!! Session::get('sweet_alert.confirmButtonText') !!}",
        confirmButtonColor: "#AEDEF4"
       // more options
      });
    </script>
   @endif

How can I send parameters from my controller to change, for example, Session::get('sweet_alert.showConfirmButton') parameter?

I was trying with the code bellow, but is not working:

    public function getDelete($id)
    {
      Session::set('sweet_alert.showConfirmButton', "true");
       Alert::warning('Delete?', '');
       return Redirect('....');
     }

Sweet alert doesn't show css image

edit and solution

Still no css images. This package needs to be updated to sweetalert2. It's better to make an if else session statement and hard code the sweet alert inside it. Alternatively, make a sweetalert.blade page and include it. e.g

    @if(session()->has('message'))
        @include('js.sweetAlert', ['message' => session()->get('message'))
    @endif

then in blade file js/sweetAlert.blade.php
https://limonte.github.io/sweetalert2/

<script>
swal($message)
</script>

Until this package gets updated use the above sample.

original

The sweet alert doesn't show the image but when I do the javascript it works well.
An image explains everything easier: https://imgur.com/a/E9V5h

code:

        use Alert;

        Alert::success('Something went wrong', 'Oops!');
        return view('debug');

Javascript code does show the image:

<script>
    swal("Good job!", "You clicked the button!", "error");
</script>

HTML not displaying

Using Laravel/Spark. Had things working somewhat, then ran into issues after doing some vue and working on the site more. I then had to add in a 'title', before my text to get the alert to show.
Now the code will not display in html. It just prints out all the code. My second issue is that whether i use info, message, alert, the icon doesn't appear. All i'm getting right now is text. Any assistance would be appreciated. Not sure where to try and debug.

This is at the end of my function in my controller.
Alert::info('test', 'Random lorempixel.com : <img src="http://lorempixel.com/150/150/">')->html(); return redirect('/challenge/'.$challenge->slug);

ErrorException : "Undefined index: title"

Hi!
Just to tell you that when you use the persistent() options before setting a message (and so a title),
we've got an error:

[2016-07-05 10:57:35] local.ERROR: exception 'ErrorException' with message 'Undefined index: title' in /usr/share/nginx/html/vendor/uxweb/sweet-alert/src/SweetAlert/SweetAlertNotifier.php:224
Stack trace:
#0 /usr/share/nginx/html/vendor/uxweb/sweet-alert/src/SweetAlert/SweetAlertNotifier.php(224): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/usr/share/ngin...', 224, Array)
#1 /usr/share/nginx/html/vendor/uxweb/sweet-alert/src/SweetAlert/SweetAlertNotifier.php(199): UxWeb\SweetAlert\SweetAlertNotifier->hasTitle()
#2 /usr/share/nginx/html/vendor/uxweb/sweet-alert/src/SweetAlert/SweetAlertNotifier.php(189): UxWeb\SweetAlert\SweetAlertNotifier->buildConfig()
#3 /usr/share/nginx/html/vendor/uxweb/sweet-alert/src/SweetAlert/SweetAlertNotifier.php(173): UxWeb\SweetAlert\SweetAlertNotifier->flashConfig()
#4 /usr/share/nginx/html/app/Http/Middleware/CanAccess.php(25): UxWeb\SweetAlert\SweetAlertNotifier->persistent()

Thanks!

Alert on ajax ?

Hello, Thanks for this awesome package, i have one problem with ajax
how do i display the alert box on ajax request ? it only works when i refresh the browser after ajax request

sweet alert button doesn't appear

Hi
I use sw-2 in my laravel project but persistent button doesn't show

alert()->warning('please wait','my title')->persistent('ok');

Button Ok doesn't show
can anyone help me?

Since Laravel 5.3 we cannot enter Javascript directly in views

What to do now? So I can not configure the sweetAlert messages. But I need a "Do you really want to delete this" dialog with "yes" and "no" option. So I got my controller with a Session::flash('sweet_alert.alert', $message, null); line.
In my view I render a partial named '_messages.blade.php where I catch the session messages.
As described in your readme I should enter the javascript here, but since the new Laravel version it will not be rendered. So I did the following:

@if(Session::has('sweet_alert.alert'))
	{{ null, alert('<a href="projects.destroy">Delete</a>')->html()->warning('Do you really want to delete this project? This action cannot be undone!', 'Warning')->html()->persistent('No') }}
@endif

I don't know why the first argument must be a string, so I entered "null". Otherwise it will give me the string as plain text in my view. When I call the html()-function as above, I got the "Delete"-link as huge title in sweetAlert and as message-text "true", followed by the "No"-Button. =(
Can anyone help me?

not working in alert in redirect()

Hi!
not working in alert in redirect()->back();
because working in return view();
why?
code not working:
return redirect()->back()
code working:
return view('view')
code alert:
\Alert::message('Hey!');
Or:
alert()->error('Error Message', 'Optional Title');

SweetAlert2 Compatibility

Most of the function are no longer working in SweetAlert2.
Example:
alert()->success('Message', 'title'); is no longer working as a Success Alert but a normal alert.

Confirmation Message With Sweet Alert.

I think "Confirmation" ( Like on delete something ) message with "Sweetalert" is not included in this package, right ? If this is included can you please tell how to use them ?

use Alert;

I put "use Alert;" my controller laravel project 5.5 but It doesn't work ? Do you have any idea why it happened ? I don't understand. I manually add provider and alias by myself still doesn't working at all..

prevent show when user press back button in browser?

I use this package in my projects and i found some problem, ex: when i created some product success alert will show. it's work correcty but when i go to create product page again and press back to previous page alert will show up again. how to resolve that?

ps.sorry for my bad english

Showing popup before action

Hi,

Is it possible using your code to be able to have a popup appear before a action is done. SO if I want to delete a user have a popup appear confirming deletion?

Thanks

Proposal

Hi,

Do you think you could add a new method alert()->newMethod('Message', 'title');?

This method will behave just like other but with NO icon (info ; success ; error). Just a title and a message.

Regards,

Sweet alert does not work well

i'm ussing laravel with last version of sweet alert and is not working beacuse, the options given in SweetAlertNotifier.php not correspond with options given in SweetAlert Doc's.

My question is, will you upgrade the library or do i have to use another library?

or

What can i do to solve the problem with the functions?

Thanks.

Cancel button

Hi!
It could be pretty cool to add the cancel button, like in this example:

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});

Or at least, maybe just permit to add some custom fields ?

Thanks !

(If you tell me it will be faster with a PR, I could do it myself, and push it.)

Alerts not showing on 5.4.11

So i am trying to at uxweb/sweet-alert to my project that is currently using 5.4.11.
I have used this on many projects before but none since i started using laravel 5.4.11

My Master Layout:

<link rel="stylesheet" href="{{url('/css/sweetalert.css')}}">
<link rel="stylesheet" href="{{url('/css/app.css')}}">
<script src="{{url('/js/sweetalert.js')}}"></script>
<script src="{{url('/js/app.js')}}"></script>
@include('sweet::alert')

My config/app.php:
UxWeb\SweetAlert\SweetAlertServiceProvider::class,

My Controller:

Alert::message('We will get back to you soon!', 'Thank you!');
return redirect()->route('home');

I have added use Auth; into my controller as well.

[QUESTION] Unknown parameter "buttons" and "icon" on v2.0

Versions

  • PHP version: 7.2.4
  • Laravel version: 5.6.*
  • Uxweb/sweet-alert version: 2.0
  • Sweetalert2: 7.26.11

here my composer.json

"require": {
        "php": "^7.1.3",
        "consoletvs/charts": "6.*",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0",
        "maatwebsite/excel": "^3.0",
        "uxweb/sweet-alert": "^2.0"
},

Configuration

  • include .css and .js files from the sweet-alert library.
  • include package to service provider and aliases in config/app.php.
  • place @include('sweet::alert') in blade.
  • call sweetalert within controller Alert::error('Something went wrong', 'Oops!');

The Problem

icon not show up
2018-08-15 1
got this message on console
2018-08-15 2

Conclusion

for now im using uxweb/sweet-alert v1.4 and sweetalert2 v7.19.2.
somehow i know it was caused by incompatibility from my sweetalert2 lib, if yes can i know which version of sweetalert2 is compatible with v2.0.
if not please tell me out which is causing the problem, or something inccorect in my setup.

show alert icon

when i use alert ,alert show successful but icon dont display ?

Alerts are not called

I places "use Alert;" on the top of my UserController.php file
and placed these in the destroy method

 public function destroy($id)
    {
        //
        Alert::warning('Warning Message', 'Optional Title');
        alert()->success('You have been logged out.', 'Good bye!');

        User::findOrFail($id)->delete();

        Session::flash('delete_user','The user has been deleted!');

        return redirect('admin/users');
    }

They didn't work.. any ideas
Thanks,

Alerts Appearing again on next page or refresh when using middleware

I am using the middleware so that standard error messages will come across as a sweet alert. When using middleware I am experience an odd quirk where once the error message is dismissed it is not being cleared from the session. If I brows to another page or refresh the page the same alert will be displayed. It only does this twice. The next page load or refresh will not have an alert. I do not see this behavior when not using the middleware.

To make sure it was not something in my applications I did a clean install of Laravel 5.3 and setup the sweet alert middleware and I got the same behavior.

Steps to reproduce.

  1. Install clean instance of Laravel 5.3.
  2. Run php artisan make:auth to get auth scaffolding.
  3. Setup env so that auth can login or present an error message.
  4. Install sweet-alert as described in the readme. (get packages, config, modify view, modify, middleware)
  5. Make a failed login attempt to see sweet alert.
  6. browse to forgot password view or refresh to see the second alert.
  7. again refresh or browse to another page to see no third alert is shown.

Issue with UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert

Hey,

I wonder why I've gotten a "Class UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert does not exist" exception.
Found out, that there is a typo in the filename under /vendor/uxweb/sweet-alert/SweetAlert/
The php file there is named ConvertMessagesIntoSweatAlert. Sweet but with -ea- instead -ee-

Greetings

Chris

persistent not showing close text

alert()->success('Staff has been deleted successfully', 'Success')->persistent('Close');
the alert produced by the above code does not have the close button
Edit!!
here is the problem
sweetalert.min.js:1 SweetAlert warning: "showConfirmButton" option has been deprecated. Please use "button" instead. More details: https://sweetalert.js.org/docs/#button e.logDeprecation @ sweetalert.min.js:1 sweetalert.min.js:1 SweetAlert warning: "confirmButtonText" option has been deprecated. Please use "button" instead. More details: https://sweetalert.js.org/docs/#button

you need to update the package to use the latest version of sweetalert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.