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

iKyzu's avatar
Level 1

Laravel and Sweetalert | Not Working on local

Hey, I have a small problem with Sweetalert, and I want to know just if it suppose to be like this or it is a bug or something is wrong.

I installed SweetAlert inside my laravel project, but somehow when I am running local and using: php artisan serve to the project to run the Sweetalert are not working, but when I am pushing the project into production mode and seperate server they are working just fine.

So my question is if I should just keep implement it and just test them when I am moving everything to production server later or this should work also on local and serve from artisan.

I am using this package of sweetalert: https://github.com/realrashid/sweet-alert

Best Regards!

0 likes
8 replies
Tray2's avatar

Show us some code and we might be able to help you?

iKyzu's avatar
Level 1

What you want see, the package is installed and published like it says inside the documentation, it’s working on production mode but not locally only.

Snapey's avatar

Everything should work in both places.... else how can you be confident publishing your site?

There is something different about the URL format between the two sites ?

iKyzu's avatar
Level 1

Only the difference is the mode local and production and ofc locally I am running it on serve while on production I am running it on a server with Apache and stuff

Snapey's avatar

open the browser network tools. Check all assets are loaded and that you don't have any red lines

iKyzu's avatar
Level 1

I checked it and yes there is a problem, I am getting this:

Uncaught ReferenceError: Swal is not defined

Swal.fire({"title":"Success Toast","text":"","timer":null,"width":null,"padding":null,"showConfirmButton":false,"showCloseButton":true,"customClass":{"container":null,"popup":null,"header":null,"title":null,"closeButton":null,"icon":null,"image":null,"content":null,"input":null,"actions":null,"confirmButton":null,"cancelButton":null,"footer":null},"toast":true,"icon":"success","position":null});

Snapey's avatar

Is the SweetAlert library loaded? Did you see it in the network requests as suggested?

iKyzu's avatar
iKyzu
OP
Best Answer
Level 1

Fixed it by adding this:

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>

Into main blade, I found this inside another tutorial of how to install sweetalert2, and it seems to work. I will test it later if I need it inside production but it doesn't hurt I guess :)

Please or to participate in this conversation.