小编Moh*_*hif的帖子

如何在laravel错误消息数组中获取错误键

我试图使用Laravel错误dump($errors)从数组中检索一个键.

该数组看起来像这样

ViewErrorBag {#169 ?
  #bags: array:1 [?
    "default" => MessageBag {#170 ?
      #messages: array:2 [?
        "name" => array:1 [?
          0 => "The name field is required."
        ]
        "role_id" => array:1 [?
          0 => "The role id field is required."
        ]
      ]
      #format: ":message"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

使用@foreach循环来获取错误消息正常.

@foreach($errors->all() as $error)
     <li>{{$error}}</li>
@endforeach
Run Code Online (Sandbox Code Playgroud)

但我想拿到namerole_id.反正有没有实现这一目标?到目前为止,我已经尝试了下面和其他一些没有运气的方法.

@foreach ($errors->all() as $key => $value)
       Key: {{ $key }}
       Value: {{ $value }}
@endforeach
Run Code Online (Sandbox Code Playgroud)

php arrays laravel laravel-5.3

5
推荐指数
2
解决办法
7682
查看次数

pusher 不回电

我正在尝试测试一个基本的推送器触发事件​​,它给我一个简单的警报和一个控制台日志,但它不起作用。从推送器控制台调试收到响应,但没有警报。我正在使用 laravel 5.3 及其路线和视图。下面是我的代码。我已经审查了敏感信息。

路由文件 web.php

Route::get('/bridge', function() {

    error_reporting(E_ALL);

    $options = array(
        'cluster' => 'ap1',
        'encrypted' => true
    );
    $pusher = new Pusher(
        'key censored',
        'secret censored',
        'app id censore',
        $options
    );

    $data['message'] = 'hello world';
    $pusher->trigger('test_channel', 'my_event', $data);

    return view('pusher');
});
Run Code Online (Sandbox Code Playgroud)

并查看 pusher.blade.php

<!DOCTYPE html>
<head>
    <title>Pusher Test</title>
    <script src="https://js.pusher.com/3.2/pusher.min.js"></script>
    <script>

        // Enable pusher logging - don't include this in production
        Pusher.logToConsole = true;

        var pusher = new Pusher('e5bbf707214a6223d044', {
            cluster: 'ap1',
            encrypted: true
        });

        var channel = …
Run Code Online (Sandbox Code Playgroud)

javascript php laravel pusher

3
推荐指数
1
解决办法
8232
查看次数

标签 统计

laravel ×2

php ×2

arrays ×1

javascript ×1

laravel-5.3 ×1

pusher ×1