mercredi 27 décembre 2017

Why looping to get data after using WHERE in Laravel?

So, here is my controller:

$topics = Topic::where('board_id', $id)->with('user')->get();
$topic = Topic::find($id);
$board = Boards::where('id', $id)->get();
return view('boards.show')->with('topics', $topics)->with('topic', $topic)->with('board', $board);

And here is the code for generating URL's:

@foreach($board as $boards)
<a href="/topics/create/">Create New Post</a>
<p>No Posts Found</p>
@endforeach

But if i'm removing foreach loop, it is giving error:

Property [id] does not exist on this collection instance.

But why do, i have to loop, if it is only getting one row from the boards table?? Any solution of doing it without running for each loop???



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zC9asd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire