删掉括号.
$user = User::find(1); $pages = $user->pages; foreach($pages as $page) { var_dump($page->name); }
如果你想急于加载它,那么使用该with方法并传递正确的参数,这将是你的关系方法的名称:
with
$user = User::with('pages')->find(1); foreach($user->pages as $page) { var_dump($page->name); }