所以,这是我的控制器:
$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);
Run Code Online (Sandbox Code Playgroud)
以下是生成URL的代码:
@foreach($board as $boards)
<a href="/topics/create/{{$boards->id}}">Create New Post</a>
<p>No Posts Found</p>
@endforeach
Run Code Online (Sandbox Code Playgroud)
但是,如果我正在删除foreach循环,它会给出错误:
Property [id] does not exist on this collection instance.
Run Code Online (Sandbox Code Playgroud)
但是为什么呢,我必须循环,如果它只从板表中获得一行?没有为每个循环运行的任何解决方案???