Latest

Thursday, July 6, 2017

PHP Laravel Variable Scope in functions

Asked by: Hillcow


I have the following code in a Laravel controller, but the given parameter variable $idea is undefined in the 'whereIn' function. How can I access $idea there? Thank you!

public static function getIdea($idea = null) {
    if ($idea != "") {
        return DB::table('test')->select('foo')
            ->whereIn('bar', function($query)
              {
                  $query->select('foobar')
                        ->from('bar2')
                        ->where('foo2', '=', $idea)
                        ->get();
              })
            ->get();
    }
}


Source

No comments:

Post a Comment

Adbox