Laravel 后期静态绑定为 static::whereIn

Laravel late static binding as static::whereIn

好的,我看了,感觉对PHP方法和变量的后期静态绑定有了一些了解。但是从this code on Laravel 5的第28行开始,它使用了withwhereIn,这是一个Laravel的集合方法。我不明白这里发生了什么,static::whereIn()。集合在哪里,以便您可以使用 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,
        ]);
    }
}

来自 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();

所以static::whereIn()指的是Tag::whereIn()static::create()

也一样