Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uxweb's avatar
Level 20

@jimmck Thanks, i see, have you tried \Alert::message('Wow!')?

Just updated the GitHub docs, fixed some typos and the one in the facade.

Thank you so much!

jimmck's avatar

@uxweb No Alert::message still does not work, only SweetMessage::message...

jimmck's avatar

@uxweb Regardless of the Facade issue. This is cool, I think controllers could possibly do some interesting things more directly with the browser. Nice stuff!!!!

uxweb's avatar
Level 20

@jimmck Wow!, that is pretty strange, a last resource is to try with the included helper:

    alert('Hello World');

Give it a try and let me know your results :)

Thanks!

uxweb's avatar
Level 20

@jimmck Sorry, this can be inside a controller method or in a route closure, like this:

Route::get('/alert', function() {
    alert('Hello World!');
    return view('app');
});
jimmck's avatar

Ok I see, yes the helper works fine...

    \Route::get('menu', function()
    {
        //SweetAlert::message('Welcome back!');
        alert('Hello World');
        return view('coverage');
    });

uxweb's avatar
Level 20

@jimmck Also, try this as it is:

\Route::get('menu', function() {
        \Alert::message('Welcome back!');
        return view('coverage');
});
jimmck's avatar

@uxweb Yes that works, so some how you have that in the Global namespace... Hey I don't recognize your flag, where are you?

jimmck's avatar

@uxweb Hi, Is there a quick way tom subclass your stylesheet into mine? I want to force/fit your blade view into a div that I control.

@extends('layouts.coverage')
@section('content')
<div id="container">
    <h1>Coverage Maintenance</h1>
    <div id="menu">
        <ul>
            <li><a href="cvg">Cvg</a></li>
            <li><a href="contypes">Manage Contact Types</a></li>
            <li><a href="levels">Manage Levels</a></li>
            <li><a href="positions">Manage Positions</a></li>
            <li><a href="teams">Manage Teams</a></li>
           </ul>
        <div id="myForm">
            <p> Welcome to the Awesomeness! </p>
            {!! Form::open() !!}
            {!! Form::text('name', 'value') !!}
            {!! Form::close() !!}
        </div>
    </div>
    <div id="app">
        <h1>App</h1>
    </div>
    <div id="mySweet">
        <p>Alerts</p>
        @include('sweet::alert')
    </div>
</div>
@stop

jimmck's avatar

@uxweb i had no idea of the time, its 4:30am in the East!!! This was cool. Nighty Nite!!

uxweb's avatar
Level 20

@jimmck Thanks, was a great night. I'm from México.

There is a way to override the stylesheet that comes with Sweet Alert, just take a look at the default and i'm sure you can define other styles for the classes.

theUnforgiven's avatar

I tried using your packages and doesn't work, either not pulling it in correctly or you didn't get around to fixing the composer/github links and docs. So i tried a different way as follows:

Pull in the SweetAlert JS & CSS files, reference them as normal in your HTML.

Then using the Laracasts Flash package (https://github.com/laracasts/flash) I created the following:

@if (Session::has('flash_notification.message'))
    <script>
        swal({
            title: "{{ ucwords(Session::get('flash_notification.level')) }}",
            text:  "{{ Session::get('flash_notification.message') }}",
            type: "{{ Session::get('flash_notification.level') }}",
            timer: 4600,
            showConfirmButton: false
        });
    </script>
@endif

This then gets the correct title of the flash message, along with the text passed through from your controller or where ever you pass it from, plus the correct type - i.e "success, error, info etc"

// Controller call

Flash::success('Your post has been created.');

Hope this helps other people and I hope the package that started this thread off can be fixed or it could just be me been a little dumb!!! :)

uxweb's avatar
Level 20

Thanks @lstables Yep, for some reason it was buggy, thanks to some of you I could make it better and stable.

Please do a composer update to get the stable version 1.0.7.

Thank you!

jeetdholakia's avatar

I followed everything mentioned here: https://github.com/uxweb/sweet-alert but output is not coming. Not getting anything. Code:

Alert::success('Your Profile Has Been Updated Successfully!', 'Profile Updated')->persistent("Close");
 //Session::flash('success', 'Your Profile Has Been Updated Successfully!');
 return redirect()->route('editProfile', Auth::user()->id);
cris's avatar

Thank you for this package, I have used in my project and I loved it. Greetings from Chile.

usak's avatar

Method [alert] does not exist on Redirect.

azwanx's avatar

Hi @uxweb , I did it as mention in docs in github.. I install the dependencies using npm.. and I found only js file. I did not found the css. How to get the css file because in the official website also did not have.

aungheinmynn's avatar

Alert doesn't show if I use with redirect() in controller.

Like

    Alert::message('success','Complete');
    Return redirect('/profile');

It works when I use with return view().

I already include @include('sweet::alert') under js cdn in layouts.

Previous

Please or to participate in this conversation.