Laravel 4 使用Laravel的上一页/下一页链接

Laravel 4 使用Laravel的上一页/下一页链接,laravel-4,navigation,Laravel 4,Navigation,我正在开发一个小的投资组合网站,我被卡住了一秒钟 因此,用户可以上传他们的排序(使用) 因此,当其他用户查看他/她的公文包时,它会按排序顺序显示,当您单击图像时,它会显示一个大图像 在这里,我想要上一个/下一个导航,以便人们可以导航 它可以工作,但我有一个问题,所以目前在我的数据库中,带有8的图像是最后一个,但因为图像是按排序顺序显示的,而id为8的图像(最后一个)位于第五位,它停止返回下一个id,它应该在那里 这是我试过的 控制器 public function show($id) {

我正在开发一个小的投资组合网站,我被卡住了一秒钟

因此,用户可以上传他们的排序(使用)

因此,当其他用户查看他/她的公文包时,它会按排序顺序显示,当您单击图像时,它会显示一个大图像

在这里,我想要上一个/下一个导航,以便人们可以导航

它可以工作,但我有一个问题,所以目前在我的数据库中,带有8的图像是最后一个,但因为图像是按排序顺序显示的,而id为8的图像(最后一个)位于第五位,它停止返回下一个id,它应该在那里

这是我试过的

控制器

public function show($id)
    {
        $photo = $this->photo->find($id);

        if(is_null($photo)) return App::abort('404');

        $previous = $this->photo->where('id', '<', $photo->id)->where('user_id', '=', $photo->user_id)->orderBy('id', 'DESC')->first();

        $next = $this->photo->where('id', '>', $photo->id)->where('user_id', '=', $photo->user_id)->orderBy('sort', 'ASC')->first();

        $this->layout->title = "Saját képek";
        $this->layout->content = View::make('photo::show')
                                 ->with('photo', $photo)
                                 ->with('previous', $previous)
                                 ->with('next', $next);
    }
公共功能显示($id)
{
$photo=$this->photo->find($id);
if(is_null($photo))返回App::abort('404');
$previous=$this->photo->where('id','',$photo->id)->where('user_id','=',$photo->user_id)->orderBy('sort','ASC')->first();
$this->layout->title=“Saját képek”;
$this->layout->content=View::make('photo::show')
->带('photo',$photo)
->带('previous',$previous)
->带('next',$next);
}
查看

<div class="ui page grid">
    <div class="ui grid">
        <div class="wide column">
            <div class="ui segment">
                <div class="photo-viev-nav">
                    @if(!empty($previous->id))
                        <a href="{{ URL::to( 'portfolio/pic/' . $previous->id ) }}" class="ui tiny button"><i class="ui left icon"></i> Vissza </a>
                    @endif
                        <strong>{{ $photo->user->name() }} potfóliója</strong>
                    @if(!empty($next))
                        <a href="{{ URL::to( 'portfolio/pic/' . $next->id ) }}" class="ui tiny button"> Következő  <i class="ui right icon"></i></a>
                    @endif
                </div>
                <div class="photo-view">
                    {{ HTML::image($photo->photoOriginal(), '', array('class' => 'ui huge image')) }}
                </div>
            </div>
        </div>
    </div>

@如果(!empty($previous->id))
@恩迪夫
{{$photo->user->name()}}potfóliója
@如果(!空($next))
@恩迪夫
{{HTML::image($photo->photoOriginal(),'',数组('class'=>'ui-mage'))}

我第二次尝试的是这个查询

$previous = $this->photo->where('id', '<', $photo->id)->where('user_id', '=', $photo->user_id)->orderBy('sort', 'ASC')->max('id');

$next = $this->photo->where('id', '>', $photo->id)->where('user_id', '=', $photo->user_id)->orderBy('sort', 'ASC')->min('id');
$previous=$this->photo->where('id','',$photo->id)->where('user\u id','=',$photo->user\u id)->orderBy('sort','ASC')->min('id');
但问题是它忽略了排序顺序


有人能给我一个提示吗?

我做了更多的实验,我有点傻,没有把重点放在id上,而是把重点放在排序顺序上,以这种方式获取id

正确查询

$previous = $this->photo->where('sort', '<', $photo->sort)->where('user_id', '=', $photo->user_id)->orderBy('', 'DESC')->first();

$next = $this->photo->where('sort', '>', $photo->sort)->where('user_id', '=', $photo->user_id)->orderBy('sort', 'ASC')->first(); 
$previous=$this->photo->where('sort','','photo->sort)->where('user\u id','=','photo->user\u id)->orderBy('sort','ASC')->first();