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

umairparacha's avatar

How to get the session data in javascript

here is my script

<script>
        @if(session()->has('success'))
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: 'Updated successfully!',
        })
        @endif
</script>

but this is not working.

0 likes
2 replies
MichalOravec's avatar
Level 75

Change it to this and it should work

@if (session()->has('success'))
    <script>
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: 'Updated successfully!',
        })
    </script>
@endif

Please or to participate in this conversation.