缺少路由,多参数语句所需的参数

时间:2018-04-12 15:13:05

标签: laravel laravel-5 laravel-5.4

我遇到了一个问题,似乎我从链接中遗漏了'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

1 个答案:

答案 0 :(得分:2)

当路由需要多个参数时,您会传入一个值数组,例如:

route('thread.show, ['slug' => $thread->slug, 'id' => $thread->id]);