【发布时间】:2018-05-19 16:24:35
【问题描述】:
我有一个 post 变量,我想将它用作我的子函数。我怎样才能做到这一点 ?当我尝试时,它显示“未定义的变量”。
控制器
public function getSingle($slug){
$post = Post::where('slug',$slug)->first();
$related_categories_posts = Post::whereHas('categories',function ($query){
$query->where('category_name', $post->categories->category_name);
})
->take(3)
->get();
return view('frontend.single')
->with('post',$post)
->with('related_categories_posts',$related_categories_posts);
}
有什么建议吗?
【问题讨论】:
-
我建议您修复代码缩进问题。
-
你没有
use。 -
@revo 好像是这样,我找不到它..
标签: php function variables laravel-5 laravel-5.5