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

时间:2016-06-30 06:54:21

标签: php laravel late-static-binding

好的,我阅读并感觉我对PHP后期静态绑定方法和变量有一些了解。但是从this code on Laravel 5中的第28行开始,它与whereIn一起使用,这是一种Laravel Collection方法。我不明白这里发生了什么,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,
        ]);
    }
}

1 个答案:

答案 0 :(得分:0)

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

也是如此