1
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;
}
}
laravel 5.1我在我的Article.php模型上創建了上述函數。這個想法是,它會檢查每個提供的語言是否存在文章的翻譯版本。嵌套的stdClass不返回預期的結果
$locales = config('app.locales');
返回:
[
"en" => "English",
"fr" => "French",
"nl" => "Dutch",
"it" => "italian",
"de" => "German",
]
現在foreach循環應該創建這些語言的嵌套stdClass的對象,但我只能接受恩:
=> {#828
+"en": {#830
+"class": "exists",
+"link": "http://multilingual.dev/articles/loading-efficiently/edit/en",
},
}
我無法理解爲什麼我不收到其他語言?
多可恥!非常感謝你這樣一個愚蠢而簡單的問題。有時它需要的只是新鮮的眼睛! – Philwn