嵌套的stdClass不返回预期的结果

时间:2017-03-23 11:09:25

标签: php oop laravel-5

var re=/^[A-Za-z]{2,2}[\-_A-Za-z]*$/;
console.log(re.test('tE_'));
console.log(re.test('Te'));
console.log(re.test('tE-'));
console.log(re.test('test'));

在laravel 5.1中,我在Article.php模型上创建了上述函数。我们的想法是,它会检查每种提供的语言是否存在翻译版本的文章。

public function quickbar()
{
    $locales = config('app.locales');
    $buttons = new \stdClass;
    foreach ($locales as $locale => $language)
    {
        $buttons->$locale = new \stdClass; 
        if($this->translate($locale))
        {
            $buttons->$locale->class = "exists";
            $buttons->$locale->link = route('articles.edit', ['slug' => $this->slug, 'locale' => $locale]);
        } else {
            $buttons->$locale->class = "missing";
            $buttons->$locale->link = route('articles.create', ['slug' => $this->slug, 'locale' => $locale]);
        }

        return $buttons;
    }
}

返回:

$locales = config('app.locales');

现在,foreach循环应该为每种语言创建一个嵌套的stdClass对象,但我只收到En:

[
 "en" => "English",
 "fr" => "French",
 "nl" => "Dutch",
 "it" => "italian",
 "de" => "German",
]

我无法理解为什么我没有收到其他语言?

1 个答案:

答案 0 :(得分:2)

您似乎已将<ul> <li>Mr. JOHN DOE</li> <li>1 extra luggage</li> <li>1 checked extra luggage for the adult will cost the passenger the following cost from the book described by airline laws<span class="extraCost"> EUR 20</span></li> </ul>放置在foreach中,因此循环将在第一个区域设置之后结束。试着把它放在foreach之后。