调用变量到子函数?

时间:2017-12-05 21:53:20

标签: php function variables laravel-5 laravel-5.5

我有一个post变量,我想使用它的子函数。我怎样才能做到这一点 ?当我尝试它时说“Undefined Variable”。

控制器

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);
}

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您需要使用docs中所述的ngAfterViewInit将此变量传递给该函数。

use
相关问题