php 如何在 Laravel 5 上添加警报?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38764421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add an alert on Laravel 5?
提问by Iqbal Nurkholik
I have a function where:
After I click the link named "hapus"
, the related data will be deleted and I want to have a popup alert to show that the data has been deleted.
*sorry for my bad english
*hapus technically means destroy
我有一个功能,其中:
单击名为 的链接后"hapus"
,相关数据将被删除,我希望有一个弹出警报来显示数据已被删除。
*抱歉我的英语不好
*hapus 技术上意味着破坏
this the code:
这是代码:
public function hapus(Request $request, $id) { DB::table('kelompok') ->where('id', $id) ->delete(); return redirect()->back(); }
回答by Peter
Use with()
in your controller
with()
在您的控制器中使用
function hapus(Request $request, $id)
{
DB::table('kelompok')
->where('id', $id)
->delete();
return redirect()->back()->with('alert', 'Deleted!');
}
In your blade template, retrieve the session
after being redirected from controller:
在您的刀片模板中,session
从控制器重定向后检索:
@if (session('alert'))
<div class="alert alert-success">
{{ session('alert') }}
</div>
@endif
回答by Han Lim
Extending @pbwned's answer,
you can also use javascript alert box
in your blade view to display the flash session/message.
扩展@pbwned 的回答,您还可以alert box
在刀片视图中使用 javascript来显示 Flash 会话/消息。
For example:
例如:
<script>
var msg = '{{Session::get('alert')}}';
var exist = '{{Session::has('alert')}}';
if(exist){
alert(msg);
}
</script>
Hope it helps =)
希望它有帮助 =)