返回数组以在laravel中查看

时间:2018-01-15 12:56:29

标签: php laravel laravel-5

我有以下控制器,将此信息数组传递给我的视图

public function index ()
{
     public function index ()
     {
        $ information = [
        'nroclients' => '10',
        'nroservices' => '20',
        'nrousuers' => '30',
        'nroordensservices' => '40',
        ];
    
         return view ('dashboard.index', compact ('information'));
     }
}

如何分别访问每个元素? 的 index.blade.php

number of clients: {{information-> nroclients}} <br>
number of services: {{information-> nroservices}}

这在我看来运行不起作用吗?

报告的错误是

  

(2/2)ErrorException试图获取非对象的属性(查看:C:\   wamp64 \ www \ sistemtest \ resources \ views \ panel \   index.blade.php)

1 个答案:

答案 0 :(得分:5)

它的数组不是对象或json所以你应该在刀片中访问这样的键:

{{$information['nroclients']}}

而不是

number of clients: {{information-> nroclients}}