2

好的,我阅读并感觉我对方法和变量的PHP后期静态绑定有所了解。但是从Laravel 5 上这段代码的第 28 行开始,它使用 with whereInwhich 是 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,
        ]);
    }
}
4

1 回答 1

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

于 2016-06-30T07:06:30.037 回答