alert - 我想在 laravel 8 中更新记录后显示警报消息
问题描述
在Controller文件中:return redirect()->route('show_record')->with('update', '内容更新成功!');
在查看文件中:
@if(session('update'))
<div class="alert alert-success alert-dismissable custom-success-box" style="margin: 15px;">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong> {{ session('update') }} </strong>
</div>
@endif
解决方案
我已经在我建立的许多网站上实现了这种东西,并且倾向于使用 Noty 来进行通知,因为它实现起来相对简单。将它加载到每个页面上,并在您的控制器中,如果您希望返回消息,请执行此操作。
在您的控制器中:
$notification = array(
'message' => 'Message wording goes here',
'alert-type' => 'success / danger / warning / info etc.'
);
return redirect()->route('your.route.here')->with($notification);
然后在网站前面的脚本部分,确保加载 Noty.js 后:
@if(Session::has('message'))
<script>
$(document).ready(function(){
var type = "{{ Session::get('alert-type', 'info') }}";
var message = "{{ Session::get('message') }}";
new Noty({
text: message,
type: type
}).show();
});
</script>
@endif
推荐阅读
- scheduler - AUTOSYS:同时获取多个作业的作业状态的命令
- python - 如何在 Flutter 和 django 中创建视频会议?
- python - 我如何在不同的坐标上对多个相同的图像进行 blit?
- java - 删除循环链表的尾部元素
- vbscript - 无法将我的变量转换为 CDate 或序列日期,出现不匹配错误
- python - 将多列上的 groupby 结果转换为字典列表
- javascript - Node.js 出错无法读取未定义的属性“数据”
- python-3.x - 按列名获取行值
- javascript - javascripts数组转换json php
- python - 从 PyCharm 的运行配置中传递 JSON 作为参数