【问题标题】:I want to show alert message after record updation in laravel 8我想在 laravel 8 中更新记录后显示警报消息
【发布时间】:2021-10-06 14:57:34
【问题描述】:

在控制器文件中: 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">&times;</a>
    <strong> {{ session('update') }} </strong>
</div>
@endif

【问题讨论】:

    标签: alert laravel-8


    【解决方案1】:

    我已经在我建立的许多网站上实现了这种东西,并且倾向于使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 2020-10-08
      • 2019-10-19
      相关资源
      最近更新 更多