我无法获得完整的路段信息/发布信息

时间:2019-09-04 23:00:23

标签: php mysql laravel slug

我正在尝试创建一个博客,当试图使上一条记录和下一条记录成为可见时,这将返回“发布”,而不是应为/ single / {slug}

的完整路径。

控制器

[includeIf "gitdir:~/git/my_professional_project/"]
    path = ~/.config/git/professional

视图

Install-Package Microsoft.NET.Sdk.Functions -Version 1.0.30-beta1

路线

  public function single($slug)
    {
        $post = Post::where('slug', $slug)->first();
        $previous = Post::where('id', '<', $post->id)->orderBy('id', 'asc')->where('status', 'PUBLISHED')->first();

        $next = Post::where('id', '>', $post->id)->orderBy('id')->where('status', 'PUBLISHED')->first();

        return view('web.single')->with(compact('post', 'previous', 'next'));
    }

单击上一个或下一个时,浏览器显示的路线为http://127.0.0.1:8000/et-autem-tempora 并且应该是 http://127.0.0.1:8000/single/et-autem-tempora

1 个答案:

答案 0 :(得分:0)

您正在执行以下操作来创建您的网址:

<a href="{{ url($next->slug) }}">
    ...
</a>

url('path')助手返回以下内容:http://{base_url}/{path}

尝试改用your named路线:

<a href="{{ route('single', ['slug' => $next->slug]) }}">
    ...
</a>

我认为这也应该起作用:

<a href="{{ route('single', $next->slug) }}">
    ...
</a>    
相关问题