我无法从控制器访问此变量$ post中的值:
刀片视图中的:
@foreach($post as $p)
<div class="col-md-3">
<div class="boxpromo">
<h4>{{ $p->title }}</h4>
<p>{{ $p->post_description }}</p>
<div class="price">
<div class="data">{{ $p->out_date }}</div>
<div class="cost">{{ $p->price }}</div>
</div>
</div>
</div>
@endforeach
在控制器中我有:
public function postSearchTransport(Request $request, Post $post){
...
// create a new query builder
$post = $post->newQuery();
// add some filters from the user in the search query
if($request->has('searchWord')){
$post->where('title', 'LIKE', '%'.$request->input('searchWord').'%');
}
...//more filters
$post->paginate(5);
return view('searchVehicle.showSearchPost')->with('post', $post);
}
我做错了什么?我应该能够在视图中访问查询结果中的所有值,但我可以这样做。
我应该将$ post std对象从控制器转换为数组然后将其返回到视图???
答案 0 :(得分:1)
您必须将paginate
方法的返回值传递给视图,如下所示:
$posts = $post->paginate(5);
return view('searchVehicle.showSearchPost')->with('post', $posts);