如何在 laravel 的视图中传递对象
How to pass object in views in laravel
我有一组 html 代码,这些代码在 foreach statement
中被调用 views
,我正在尝试推送 array of object
以获得观看次数 controller
。
以下是我的控制器代码:
public function get_template($id)
{
$template = Template::findOrFail($id);
$getplugin = json_decode($template->templatedata);
$plugins = Plugin::all();
$userid = $template->user->id;
return view('nitseditor.test', ['plugins' => $plugins, 'template'=> $template, 'getplugin' => $getplugin, 'userid' => $userid]);
}
在我的 浏览量中 我是这样打电话的:
@foreach($getplugin as $renderer)
@include('themes.' . $template->theme->name . '.Plugins.' . $plugins->find($renderer)->type . '.' . $plugins->find($renderer)->id, ['content' => $plugins->find($renderer)->userplugins()->whereUserId($userid)->first()->pivot->contents])
@endforeach
Views or HTML code 正在 generated:
<div id="slideshow">
<div class="revolution-slider">
<ul>
<!-- SLIDE -->
@foreach($content->slider as $sliders)
<li data-transition="{{ $sliders->transition }}" data-slotamount="{{ $sliders->slotamount }}" data-masterspeed="{{ $sliders->masterspeed }}">
<!-- MAIN IMAGE -->
<img src="{{ URL::asset($sliders->url) }}" alt="">
</li>
@endforeach
</ul>
</div>
</div>
现在我收到
错误
Trying to get property of non-object (View: C:\wamp\www\NitsEditor\resources\views\themes\Miracle\Plugins\Slider.blade.php) (View: C:\wamp\www\NitsEditor\resources\views\themes\Miracle\Plugins\Slider.blade.php)
在 foreach loop
中执行 diedump
以下代码时:
foreach ($getplugin as $item){
$plugincontents[] = Plugin::findOrFail($item)->userplugins()->whereUserId($userid)->first()->pivot->contents;
}
dd($plugincontents);
我能够得到 JSON output
,其中包含该特定视图的信息。像下面这样:
array:2 [▼
0 => "{"slider": [{"url": "img/home/bg.jpg", "slotamount": "7", "transition": "zoomin", "masterspeed": "1500"}, {"url": "img/home/bg2.jpg", "slotamount": "7", "transition": "zoomout", "masterspeed": "1500"}, {"url": "img/home/LOMEg.png", "slotamount": "7", "transition": "slidedown", "masterspeed": "1500"}]}"
1 => "{"logo": {"logolink": "index.html", "logoimage": "img/home/nitseditorlogo.png"}, "pages": [{"pagelink": "index.html", "pagename": "Mysite"}, {"pagelink": "templates.html", "pagename": "Templates"}, {"pagelink": "aboutus.html", "pagename": "About Us"}, {"pagelink": "contactus.html", "pagename": "Contact Us"}]}"
]
请帮帮我。谢谢。
而不是 $getplugin = json_decode($template->templatedata);
使用 $getplugin = json_decode($template->templatedata,true);
好吧,在进行交叉检查时,我开始知道我需要 json_decode
在视图中查看数据。我试过了,得到了结果,
在我的 Views 中,我对数组做了 json_decode
,如下所示:
@foreach($getplugin as $renderer)
@include('themes.' . $template->theme->name . '.Plugins.' . $plugins->find($renderer)->type . '.' . $plugins->find($renderer)->id, ['contents' => json_decode($plugins->find($renderer)->userplugins()->whereUserId($userid)->first()->pivot->contents)])
@endforeach
终于得到了想要的结果。
我有一组 html 代码,这些代码在 foreach statement
中被调用 views
,我正在尝试推送 array of object
以获得观看次数 controller
。
以下是我的控制器代码:
public function get_template($id)
{
$template = Template::findOrFail($id);
$getplugin = json_decode($template->templatedata);
$plugins = Plugin::all();
$userid = $template->user->id;
return view('nitseditor.test', ['plugins' => $plugins, 'template'=> $template, 'getplugin' => $getplugin, 'userid' => $userid]);
}
在我的 浏览量中 我是这样打电话的:
@foreach($getplugin as $renderer)
@include('themes.' . $template->theme->name . '.Plugins.' . $plugins->find($renderer)->type . '.' . $plugins->find($renderer)->id, ['content' => $plugins->find($renderer)->userplugins()->whereUserId($userid)->first()->pivot->contents])
@endforeach
Views or HTML code 正在 generated:
<div id="slideshow">
<div class="revolution-slider">
<ul>
<!-- SLIDE -->
@foreach($content->slider as $sliders)
<li data-transition="{{ $sliders->transition }}" data-slotamount="{{ $sliders->slotamount }}" data-masterspeed="{{ $sliders->masterspeed }}">
<!-- MAIN IMAGE -->
<img src="{{ URL::asset($sliders->url) }}" alt="">
</li>
@endforeach
</ul>
</div>
</div>
现在我收到
错误Trying to get property of non-object (View: C:\wamp\www\NitsEditor\resources\views\themes\Miracle\Plugins\Slider.blade.php) (View: C:\wamp\www\NitsEditor\resources\views\themes\Miracle\Plugins\Slider.blade.php)
在 foreach loop
中执行 diedump
以下代码时:
foreach ($getplugin as $item){
$plugincontents[] = Plugin::findOrFail($item)->userplugins()->whereUserId($userid)->first()->pivot->contents;
}
dd($plugincontents);
我能够得到 JSON output
,其中包含该特定视图的信息。像下面这样:
array:2 [▼
0 => "{"slider": [{"url": "img/home/bg.jpg", "slotamount": "7", "transition": "zoomin", "masterspeed": "1500"}, {"url": "img/home/bg2.jpg", "slotamount": "7", "transition": "zoomout", "masterspeed": "1500"}, {"url": "img/home/LOMEg.png", "slotamount": "7", "transition": "slidedown", "masterspeed": "1500"}]}"
1 => "{"logo": {"logolink": "index.html", "logoimage": "img/home/nitseditorlogo.png"}, "pages": [{"pagelink": "index.html", "pagename": "Mysite"}, {"pagelink": "templates.html", "pagename": "Templates"}, {"pagelink": "aboutus.html", "pagename": "About Us"}, {"pagelink": "contactus.html", "pagename": "Contact Us"}]}"
]
请帮帮我。谢谢。
而不是 $getplugin = json_decode($template->templatedata);
使用 $getplugin = json_decode($template->templatedata,true);
好吧,在进行交叉检查时,我开始知道我需要 json_decode
在视图中查看数据。我试过了,得到了结果,
在我的 Views 中,我对数组做了 json_decode
,如下所示:
@foreach($getplugin as $renderer)
@include('themes.' . $template->theme->name . '.Plugins.' . $plugins->find($renderer)->type . '.' . $plugins->find($renderer)->id, ['contents' => json_decode($plugins->find($renderer)->userplugins()->whereUserId($userid)->first()->pivot->contents)])
@endforeach
终于得到了想要的结果。