uxweb / sweet-alert Goto Github PK
View Code? Open in Web Editor NEWA simple PHP package to show SweetAlerts with the Laravel Framework
License: MIT License
A simple PHP package to show SweetAlerts with the Laravel Framework
License: MIT License
Class 'App\Http\Controllers\Alert' not found
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
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!
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 ;(
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..
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
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.
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.
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>
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
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.
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.
php artisan make:auth
to get auth scaffolding.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
I followed all installation instructions and there is no sweetalert.css in my project folder at all, checked node_modules as well.
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;
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?
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 ?
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!"});
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
According to their documentation seems like that kay might change?
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!
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,
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,
:)
There are a few features that don't work in combination with SweetAlert 2.
Is there any plan to upgrade this package to be swal-2.x friendly?
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');
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');
when i use alert ,alert show successful but icon dont display ?
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
There is a typo in the middleware section \UxWeb\SweetAlert\ConvertMessagesIntoSwetAlert::class,
. It should read \UxWeb\SweetAlert\ConvertMessagesIntoSweatAlert::class,
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.
Please add this feature
thanks
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
Would love to have the ability to define position from the function call in a controller.
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.
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,
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?
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
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
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?
Please advice, how to localize alert messages?
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 ?
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.
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
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?
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.)
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);
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?
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('....');
}
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
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"
},
@include('sweet::alert')
in blade.Alert::error('Something went wrong', 'Oops!');
icon not show up
got this message on console
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.