I'm having trouble getting access to a variable that is available outside of my method call. (Using Laravel) An example:
print "Here is my name: $name\n";
return Foo::find(1)->whereHas('bar', function($q) {
global $name;
print "Unfortunately this name is blank: " . $name;
$q->where('name', 'like', '%' . $name . '%');
})->first();
$name inside the whereHas function is always blank. If I don't declare it as $global, then I get a warning that $name doesn't exist at all. How do I get access to it?