eloquent - How to pass object in views in laravel -
i'm having set of html codes being called in foreach statement
in views
, i'm trying push array of object
views through controller
.
following controller code:
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]); }
in views i'm calling this:
@foreach($getplugin $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 being generated:
<div id="slideshow"> <div class="revolution-slider"> <ul> <!-- slide --> @foreach($content->slider $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>
now i'm getting error of
trying property of non-object (view: c:\wamp\www\nitseditor\resources\views\themes\miracle\plugins\slider\2.blade.php) (view: c:\wamp\www\nitseditor\resources\views\themes\miracle\plugins\slider\2.blade.php)
while executing diedump
below code in foreach loop
:
foreach ($getplugin $item){ $plugincontents[] = plugin::findorfail($item)->userplugins()->whereuserid($userid)->first()->pivot->contents; } dd($plugincontents);
i'm able json output
holds information of particular view. below:
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"}]}" ]
please me out. thanks.
instead of $getplugin = json_decode($template->templatedata);
use $getplugin = json_decode($template->templatedata,true);
Comments
Post a Comment