我在显示表中的数据时遇到问题,更准确地向我显示一个json对象。
如何解决此问题,因为我只需要显示标题即可。
我尝试了 json_decode ,但是抛出了一个错误,该错误是预期的字符串,一个数组已通过
AppServiceProvider:
view()->composer('*', function($view){
$results = [];
$results['zone'] = Zone::all()->last();
$results['tourism'] = Tourism::all()->last();
$results['business'] = Business::all()->last();
$results['culture'] = Culture::all()->last();
$results['education'] = Education::all()->last();
$results['inhabitant'] = Inhabitant::all()->last();
$results['investor'] = Investor::all()->last();
$results['senior'] = Senior::all()->last();
$results['sport'] = Sport::all()->last();
$view->with('sidebar', $results);
});
Sidebar.blade.php:
@foreach($sidebar as $type => $list)
@include('pages.sidebar-components.'. $type, ['items' => $list])
@endforeach
例如一个侧边栏组件视图( Business.blade.php ):
{{ $list }}
结果:
{"id":1,"title":"test","description":"test","path":"dsadsa"}
我需要:
{id:1,title:"test",description:"test",path:"dsadsa"}
我尝试解码json,但是收到预期字符串的错误,传递了数组
答案 0 :(得分:0)
我的上帝...
我刚刚删除了-> last();来自Sport :: all()-> last();而且有效。解决,关闭。