How to make alert with SweetAlert in Laravel

I would like to use SweetAlert to display my data.

I did my function

public function registration()
        $url = URL::signedRoute(

          return redirect('users')->with('success','$url');

and route that goes with it

Route::get('registration', [AppHttpControllersUserController::class, 'registration'])->name('registration');

The problem is with message, since I downloaded SweetAlert with composer I should probably got everything working, but then when I try to execute my class with button threw the route:

<a href="{{route('registration')}}"><button type="button" class="btn btn-outline-primary">{{ __('Registration link') }}</button></a>
        <div class= "alert alert-succes">

Nothing pops up(when it should)

What might be wrong with it?


When you use ->with() it means, store items in the session for the next request.

return redirect('users')->with('success', '$url');

Here comes the question. What do you do after this?

Create a notification information or an alert (popup with SweetAlert)?

If it will be used as a notification, your code has no problem. If you want to make alert (popup with SweetAlert), your understanding is wrong.

Just because the class you are using uses the name alert, doesn’t mean it make an alert with SweetAlert.

To use SweetAlert, you can add JavaScript in the header or before the </body> tag:

@if($message = session('succes_message'))
swal("{{ $message }}");

Or to use SweetAlert2 :

@if($message = session('succes_message'))
  'Good job!',
  '{{ $message }}',

If you are confused about placing the script in a specific blade view, please read my answer here.