gpt4 book ai didi

laravel - Laravel 返回错误后如何显示 Bootstrap 通知/toast (MDBootstrap)

转载 作者:行者123 更新时间:2023-12-04 01:14:00 25 4
gpt4 key购买 nike

我正在做一个 Instagram 风格的小项目,但具有基本功能 使用 Larvel 和 MDBootstrap .

Showing my design

我正在制作表格来编辑个人信息。使用 有效Laravel , 我想当 Laravel 返回表单错误,它在表单页面中显示错误的“Toast 通知”。

这些“toast”通知是通过单击按钮触发的,它们在 HTML 中没有正文,它们可以在您调用它们时使用。

showing "toast notification"

我可以做些什么来检测错误,触发这个“toast”而无需按下按钮?谢谢

最佳答案

我知道如果 Laravel 返回错误,您需要举杯 toast 。
让我提出两个解决方案。
1.使用toastr
在你的主模板文件中放这个:

    @if (session('error'))
<script>toastr.error('<?php echo session('error'); ?>')</script>
@endif
并且不要忘记把它放在你的主 js 文件中:
    $('.toast').toast({
delay:2000,
// Other options
});
2.使用Bootstrap原生toast
在你的主模板文件中放这个:
    @if (session('error'))
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded mr-2" alt="...">
<strong class="mr-auto">Bootstrap</strong>
<small class="text-muted">11 mins ago</small>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
@endif
并且不要忘记把它放在你的主 js 文件中:
$('.toast').toast({})

关于laravel - Laravel 返回错误后如何显示 Bootstrap 通知/toast (MDBootstrap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54673102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com