Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert Facade doesn't work! #115

Open
mosi3883 opened this issue Jan 7, 2020 · 13 comments
Open

Alert Facade doesn't work! #115

mosi3883 opened this issue Jan 7, 2020 · 13 comments

Comments

@mosi3883
Copy link

mosi3883 commented Jan 7, 2020

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

@robertotcestari
Copy link

same here.

@uxweb
Copy link
Owner

uxweb commented Jan 10, 2020

@mosi3883 @robertotcestari

Are you importing the whole namespace for the facade?

@mosi3883
Copy link
Author

I used use Alert;

@ijarinz
Copy link

ijarinz commented Jan 13, 2020

same here :(

@uxweb
Copy link
Owner

uxweb commented Jan 13, 2020

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

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

@ijarinz
Copy link

ijarinz commented Jan 14, 2020

@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

@mosi3883
Copy link
Author

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

@uxweb
Copy link
Owner

uxweb commented Jan 14, 2020

@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).

@ijarinz
Copy link

ijarinz commented Jan 15, 2020

@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.

@insomniac-uks
Copy link

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

@msaifull
Copy link

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

@uxweb
Copy link
Owner

uxweb commented Jul 25, 2021

@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
Copy link
Owner

uxweb commented Jul 25, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants