laravel - Laravel 返回错误后如何显示 Bootstrap 通知/toast (MDBootstrap)
问题描述
我正在做一个 Instagram 风格的小项目,但具有使用 Larvel 和 MDBootstrap的基本功能。
我正在制作表格来编辑个人信息。使用Laravel是有效的,我希望当Laravel返回表单错误时,它会在表单页面中显示错误的“Toast 通知”。
这些“toast”通知是通过单击按钮触发的,它们在 HTML 中没有正文,它们可以在您调用它们时使用。
我可以做些什么来检测错误,触发这个“toast”而无需按下按钮?谢谢
解决方案
我知道如果 Laravel 返回错误,您需要举杯祝酒。让我提出两个解决方案。
1.使用烤面包机
在你的主模板文件中放这个:
@if (session('error'))
<script>toastr.error('<?php echo session('error'); ?>')</script>
@endif
并且不要忘记把它放在你的主 js 文件中:
$('.toast').toast({
delay:2000,
// Other options
});
2.使用Bootstrap原生吐司
在你的主模板文件中放这个:
@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">×</span>
</button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
@endif
并且不要忘记把它放在你的主 js 文件中:
$('.toast').toast({})
推荐阅读
- python - Python 错误“列表”对象没有属性“is_Number”
- python - 有没有办法在使用 tqdm 和“wb”模式时制作合并 PDF 的进度条?
- django - 是否可以重建一棵树?
- biztalk - BizTalk - 获取每个应用程序的接收和发送消息计数
- python - Python多线程:如何在每次迭代中创建一个顺序线程来处理某些东西
- java - 布尔值是否隐含地为真?
- angular - VS Code 在 Angular getter 函数中找不到“get”的名称,有什么解决方法吗?
- azure - Azure 订阅已结束。我现在如何导出数据库?
- audio - 如何将文本文件中的原始音频样本转换为在每个点具有前导 n 前导频率的列表?
- spark-streaming - Databricks Delta 表更改十进制(10,0)到十进制(38,18)转换的列不起作用