我遇到了一个问题,似乎我从链接中遗漏了'slug',如果我输入$ slug我得到一个未定义的变量,关于如何定义该按钮中的slug的任何想法? 缺少[Route:thread.show] [URI:forum / {slug} / t = {id}]所需的参数。
控制器:
public function show($slug)
{
//
$forum = Forum::where('slug', '=', $slug)->first();
$thread = Thread::all()->sortBy('created_at');
return view('forum.show')->with('forum', $forum)->withThread($thread);
}
视图:
@foreach($forum->threads as $threads)
<a href="{{route('thread.show', $threads->id)}}"><p>{{$threads->threadname}}</p></a>
@endforeach
答案 0 :(得分:2)
当路由需要多个参数时,您会传入一个值数组,例如:
route('thread.show, ['slug' => $thread->slug, 'id' => $thread->id]);