i have following code
in controller
public function ViewPost($id)
{
$viewpost= Post::find($id);
return view('Guest.viewpost', ['viewpost'=>$viewpost]);
}
in view
@foreach($viewpost as $val)
<br>
Post title=
<a href="viewpost/{{$val->id}}" >{{$val->post_title}}</a>
<br>
Post content={{$val->post_content}}
<br> <br>
Featured Image=<img src="{{$val->featured_image}}" height="150" width="150">
@endforeach
but above code thow an error Trying to get property of non-object.so i tried following way
$val['post_title'];
the above code wont throw an error nor displaying output.
if i print in controller it display output but same in view if i print it give error
print_r($viewpost);
I am using laravel 5.1.Can any one tell us what i am doing wrong ?.Thank you.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1fQuEaG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire