php - How to pass out of scope variables to anonymous function -
i new in php.
i want create function link this.
public static function cat_post($category, $limit, $top) { $posts = post::wherehas('categories', function($q) { $q->where('name', 'like', $name); $q->where('top', 'like', $top); })->take($limit)->get(); }
but got
undefined variable "name"
please me. how create function....
use below:
public static function cat_post($category, $limit, $top) { $posts = post::wherehas('categories', function($q) use ($name, $top) { $q->where('name', 'like', $name); $q->where('top', 'like', $top); })->take($limit)->get(); }
have here
Comments
Post a Comment