sweet-alert
sweet-alert copied to clipboard
Alert Facade doesn't work!
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
same here.
@mosi3883 @robertotcestari
Are you importing the whole namespace for the facade?
I used use Alert;
same here :(
@mosi3883 Could you import the Facade using the whole namespace?
use UxWeb\SweetAlert\SweetAlert;
// or
use SweetAlert;
@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
I decided to use main script and don't use packages so feel free to close this issue
@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
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.
im facing same problem, alert helper function works but facade doesnot work. im using laravel 8. Please any suggestion, why its behaving like this?
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
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
@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.