【发布时间】:2020-10-14 20:24:02
【问题描述】:
我在 laravel 8 中使用 toastr 我在控制器中的代码 我所有的代码都在这里,希望大家有所帮助
$flight = new contact;
$flight->name = $request->name;
$flight->email = $request->email;
$flight->message = $request->message;
$flight->save();
$notification = array(
'message' => 'Message send Successfully',
'alert-type' => 'success'
);
return redirect('/')->with($notification);
和javascript文件
<script>
@if (Session::has('message'))
var type = "{{ Session::get('alert-type', 'info') }}";
switch(type)
{
case 'info':
toastr.info("{{ Session::get('message') }}");
break;
case 'warning':
toastr.warning("{{ Session::get('message') }}");
break;
case 'success':
toastr.success("{{ Session::get('message') }}");
break;
case 'error':
toastr.error("{{ Session::get('message') }}");
break;
}
@endif
</script>
保存数据后不显示警报但数据存在于数据库中
【问题讨论】: