I cant figure out why, but I can var_dump($cPage) and get the complete array, but I can't access my variable in the view. {{ $cPage->code }} allways gets me an "Undefined property: Illuminate\Database\Eloquent\Collection::$code" error. Can anyone explain me why?
Controller:
public function getPages($lang, $slug)
{
$cPage = Page::join('langs', 'langs.id', '=', 'pages.lang_parent_id')
->where('slug', '=', $slug)
->where('code', '=', $lang)
->get();
$mainPages = Page::where('parent_id', null)
->get();
$allPages = $this->getAllPages($mainPages);
return View::make('index')
->with('cPage', $cPage)
->with('mainPages', $mainPages)
->with('allPages', $allPages);
}
View
<ul class="nav">
<li class="dropdown">
<button type="submit" class="btn dropdown-toggle icon-white" data-toggle="dropdown"> {{ $cPage->code }} <b class="caret"></b></button>
<ul class="dropdown-menu pull-right">
<li><a href="#">Português</a></li>
<li><a href="#">English</a></li>
</ul>
</li>
</ul>
var_dump($cPage)
array(1) { [0]=> array(9) { ["id"]=> string(1) "1" ["parent_id"]=> NULL ["lang_parent_id"]=> string(1) "1" ["translate_parent_id"]=> NULL ["title"]=> string(8) "Clientes" ["slug"]=> string(8) "clientes" ["sort"]=> NULL ["name"]=> string(10) "Português" ["code"]=> string(2) "pt" } }