sweet-alert icon indicating copy to clipboard operation
sweet-alert copied to clipboard

Alert Facade doesn't work!

Open mosi3883 opened this issue 5 years ago • 13 comments

when I'm using alert()->message('Message', 'Optional Title'); it's work but when I'm using Alert::message('Message', 'Optional Title'); it's not working the session doesn't contain any sweet alert data When I'm using Facade No error on Laravel no error on console

mosi3883 avatar Jan 07 '20 12:01 mosi3883

same here.

robertotcestari avatar Jan 08 '20 17:01 robertotcestari

@mosi3883 @robertotcestari

Are you importing the whole namespace for the facade?

uxweb avatar Jan 10 '20 16:01 uxweb

I used use Alert;

mosi3883 avatar Jan 10 '20 17:01 mosi3883

same here :(

ijarinz avatar Jan 13 '20 09:01 ijarinz

@mosi3883 Could you import the Facade using the whole namespace?

use UxWeb\SweetAlert\SweetAlert;
// or
use SweetAlert;

uxweb avatar Jan 13 '20 21:01 uxweb

@mosi3883 Could you import the Facade using the whole namespace?

use UxWeb\SweetAlert\SweetAlert;
// or
use SweetAlert;

use UxWeb\SweetAlert\SweetAlert; then using SweetAlert::message doesnt work

use UxWeb\SweetAlert\SweetAlert; then alert()->message('Message', 'Optional Title'); works

use SweetAlert; then using SweetAlert::message throws 'Class not found'

use Alert; then Alert::message doesn't work

use Alert; then alert()->message('Message', 'Optional Title'); works

ijarinz avatar Jan 14 '20 00:01 ijarinz

I decided to use main script and don't use packages so feel free to close this issue

mosi3883 avatar Jan 14 '20 02:01 mosi3883

@ijarinz

Facade and helper function usage are not related. If you want to use the facade just import it with:

use UxWeb\SweetAlert\SweetAlert;

// ...

SweetAlert::message(/*args*/);

// ...

If you want to use the helper function there's no need to import the Facade. Helper function is able to resolve the underlying service class.

The case for use SweetAlert failing relates on how the alias is defined in the config/app.php file. You can name the alias whatever you want:

// config/app.php

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

Then, the tip is that you can import a facade by it's Alias only if it's defined, otherwise you need to import the facade using it's FQN (fully qualified name).

uxweb avatar Jan 14 '20 19:01 uxweb

@uxweb

Hi. Thanks for the clarification.

use UxWeb\SweetAlert\SweetAlert;

// ...

SweetAlert::message(/*args*/);

// ...

This doesnt work.

We do have

'Alert' => UxWeb\SweetAlert\SweetAlert::class,

in our config/app.php and have been using Alert::message all these while.

I reverted back to 2.0.1 in the mean time.

Thanks for your hard work.

ijarinz avatar Jan 15 '20 00:01 ijarinz

im facing same problem, alert helper function works but facade doesnot work. im using laravel 8. Please any suggestion, why its behaving like this?

insomniac-uks avatar Dec 17 '20 12:12 insomniac-uks

im facing same problem, alert helper function works but facade doesnot work. im using laravel 8. Please any suggestion, why its behaving like this?

use Auth;

Alert()->success('Message', 'Optional title');

msaifull avatar Jul 25 '21 00:07 msaifull

@msaifull

It seems to be broken. I'm sorry, right I don't have the time to invest in this project, but you can send a pull request to fix it.

Thanks

uxweb avatar Jul 25 '21 00:07 uxweb

@msaifull

The main problem is that time ago I added a __destruct() method in hope Laravel would call it and set the configuration on the session storage, but it seems Laravel is not calling this method.

Maybe the way to fix it is to call the flashConfig() method on each other method that mutates the configuration.

uxweb avatar Jul 25 '21 00:07 uxweb