2017-01-26 1 views
0

laravel 5.3 を使用してコントローラからビューに記事を渡そうとしています。{{$ selectedArticle}}を使用していますフル出力:Laravel - > with()をブレードに表示できません(未定義のプロパティ)

[{"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を使用してみたときに、私は次のエラーを取得する:

私はseparatly品の性質上呼び出すことができますどのように

Undefined property: Illuminate\Support\Collection::$id

?あなたはビューに渡している変数が配列であるなど、配列を使用すると、ループすべき値を表示する

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); 
} 

答えて

0

:私のコントローラのコード

(...、タイトル、IDを呼び出します)この。

@foreach($selectedArticle as $article) 

    {{ $article->id }} 

@endforeach 

それとも、このように、最初の行を取得するにはfirst()機能を使用して1つのオブジェクトのみを選択したい場合:

$article = DB::table('articles')->orderBy('id')->where(['id'=> $id])->first(); 
関連する問題