Reputation: 33
I'm trying to render a sweet alert UI in my controller action , however It's not showing at all and no error message is thrown.
<form action="/delete/{{$diary->id}}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn text-danger mx-1">delete</button>
</form>
and route is Route::delete('/delete/{id}', [DiaryController::class, 'destroy'])->whereNumber('id');
I'm including sweet-alert script in master layout
@include('sweetalert::alert')
</body>
and the controller action is
public function destroy($id = null){
Alert::error('Are you sure you want to delete ' . $id, 'Error Message');
return view('diaries');
}
I followed the instruction provided on the official website documentation https://realrashid.github.io/sweet-alert/
I would appreciate any help, thanks in advance.
Upvotes: 1
Views: 1725
Reputation: 33
I finally figured the answer in my alert.blade.php I added the script type = javascript
<script type="javascript">
Swal.fire({!!Session::pull('alert.config')!!}); // not working
</script>
By removing type="javascript" it worked like a charm .
<script>
Swal.fire({!!Session::pull('alert.config')!!}); // working
</script>
Upvotes: 1