php - 如何在 Laravel 中显示多个 Toast 通知

标签 php arrays laravel notifications toastr

我正在尝试使用 toastr 显示多个通知但只显示第一条消息。

return response()->json(array(
                             'status'=>'warning',
                             'message'=> 'Invoiced could not sent!',
                             'status'=>'success',
                             'message'=> 'item successfully modified!'
));

输出:

{ status: "success", message: "Booking successfully modified!" }

message: "Booking successfully modified!"

status: "success"

enter image description here

如果您能告诉我如何显示多条消息(如上面的屏幕截图所示),我将不胜感激。有些通知可能具有警告状态,有些通知可能具有成功状态。

最佳答案

您执行此操作的方式是覆盖数组的 statusmessage 属性。

考虑为这样的事情创建一个数组的数组:

return response()->json(array(
    'messages' => array(
        array(
            'status'=>'warning',
            'message'=> 'Invoiced could not sent!'
        ),
        array(
            'status'=>'success',
            'message'=> 'item successfully modified!'
        )
    )
));

然后您可以迭代每个元素。

$.ajax({
    // Your current configuration
}).done(function (response) {
    for(var msg in response.messages) {
        var status = response.messages[msg]['status'];
        var message = response.messages[msg]['message'];
        toastr[status](message);
    } 
});

关于php - 如何在 Laravel 中显示多个 Toast 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46866762/

相关文章:

php - 浮点值不匹配

php - PHP 中 objectAtIndex 的等效项

javascript - 基于嵌套数组中匹配值的angularjs过滤器

php - 如何在php中将计算列添加到mysql查询结果中?

php - JQGrid 使用 OnSelectRow 在另一个网格上加载数据

java - 从解析对象中获取ArrayList

php - Laravel、@lang 和 strtolower()

Laravel 更新不起作用告诉 _method 未知列

mysql - Laravel 5.4 迁移 key 太长错误

php - 无法通过 fsockopen 在 PHP 中建立 TLS 连接