【发布时间】:2017-06-11 22:06:13
【问题描述】:
我正在尝试使用 laravel 5.3 将文章从我的控制器传递到我的视图 如果我只使用 {{ $selectedArticle }} 我会得到完整的输出:
[{"id":5,"title":"Up up and awayy",
"link":"www.google.be",
"points":0,
"userID":1,
"isDeleted":"FALSE",
"created_at":"2017-01-25 23:53:19",
"updated_at":"2017-01-25 23:53:56"
}]
但是当我尝试使用$selectedArticle->id 时,我收到以下错误:
未定义属性:Illuminate\Support\Collection::$id
如何分别调用文章的属性? (调用 id、title、...)
我的控制器代码:
public function index($id)
{
$comments = DB::table('comments')->orderBy('id')->where(['artikelID' => $id, 'isDeleted' => 'FALSE'])->get();
$article = DB::table('articles')->orderBy('id')->where(['id'=> $id])->get();
return view('comments.comments')
->with('storedComments', $comments)
->with('artikelid',$id)
->with('selectedArticle', $article);
}
【问题讨论】:
标签: arrays laravel-5.3 blade laravel-blade