uxweb / sweet-alert

A simple PHP package to show SweetAlerts with the Laravel Framework
MIT License
834 stars 209 forks source link

not show sweetalert laravel5.8 #118

Open HazemAyyad opened 4 years ago

HazemAyyad commented 4 years ago

i used use UxWeb\SweetAlert\SweetAlert; SweetAlert::success('Success Message', 'Added Done '); i used in blade.php

@include('sweet::alert') i used in // config/app.php 'providers' => [ UxWeb\SweetAlert\SweetAlertServiceProvider::class, ];

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

tkaarlas commented 4 years ago

Having the same issue with Laravel 6. Only way I get this to work is if I use alert()->message('Message', 'Optional Title'); and also session based swal() in my script section, which is yielded into main layout file. For some reason in main layout file's script section the dynamic swal() doesn't do the job.

And Facade method triggers nothing. :/ (Plus, @include('sweet::alert') has to be in the main layout, otherwise it won't work either.)

I posted this comment here, but it's kinda related also to #93 and #115. I installed this via composer & npm, also tried with CDN. Also noticed that it didn't create its alias Alert by itself, so I had to use FQN.

uxweb commented 4 years ago

@tkaarlas @HazemAyyad

Looks like there's some bug related to the Facade. I'm digging into the code to find out the bug. All help is appreciated!

juliomotol commented 4 years ago

Hi, Sharing some of my findings

First Controller Action

SweetAlert::error('Some error');

dd(Session::get('sweet_alert')); // Displays the sweet alert config

return redirect()->route('some-route');

'some-route' Controller action

dd(Session::get('sweet_alert')); // Displays 'null'

The helper alert()->error() doesn't work for me either. Im running Laravel 6.x. There might be some problems with the Session dependency or something has changed with how Laravel redirects. Will continue looking further and will update you when something comes up.

juliomotol commented 4 years ago

Hi, I found the problem with the facades. the __destruct method is not triggered.

https://github.com/uxweb/sweet-alert/blob/fb88b736c86131c18254216e79559f4d93e08ca6/src/SweetAlert/SweetAlertNotifier.php#L360-L363

I then tried placing the $this->flashConfig() inside message() method and it works as intended.

rabishmuel commented 4 years ago

THANKS "juliomotol" ! It's work for me ! -> I add "$this->flashConfig();" into the public function "message ()"

did you put "$this->flashConfig();" in the __destruct() or did you remove it?

juliomotol commented 4 years ago

did you put "$this->flashConfig();" in the __destruct() or did you remove it?

Neither, I was just trying to figure out what could have been the problem and tried hacking the code a bit. I'd suggest using the helper functions for now until this is fixed.