Ok, I read and feel I have some understandings about PHP late static binding for methods and variables. But from line 28 in this code on Laravel 5, it uses with whereIn
which is a Laravel Collection method. I don't understand what's going on here, static::whereIn()
. Where is the collection so that you can use whereIn()
.
/**
* Add any tags needed from the list
*
* @param array $tags List of tags to check/add
*/
public static function addNeededTags(array $tags)
{
if (count($tags) === 0) {
return;
}
$found = static::whereIn('tag', $tags)->lists('tag')->all();
foreach (array_diff($tags, $found) as $tag) {
static::create([
'tag' => $tag,
'title' => $tag,
'subtitle' => 'Subtitle for '.$tag,
'page_image' => '',
'meta_description' => '',
'reverse_direction' => false,
]);
}
}
An example from php.net:
class a
{
static protected $test = "class a";
public function static_test()
{
echo static::$test; // Results class b
echo self::$test; // Results class a
}
}
class b extends a
{
static protected $test = "class b";
}
$obj = new b();
$obj->static_test();
So static::whereIn()
refers to Tag::whereIn()
. Same goes for static::create()