简体   繁体   English

Laravel 5下一页和上一页

[英]Laravel 5 next and previous paging

Hello I have a list of max 5 articles in my homepage but I have many more articles and I would like to show these articles in other pages. 您好,我的首页上最多列出了5篇文章,但我还有更多文章,我想在其他页面中显示这些文章。 So when I see more old posts, I would like to do a pagination like user home page / 1 when I get it as a result of posting it as url. 因此,当我看到更多旧帖子时,由于将其发布为url,因此我希望进行分页,例如用户主页/ 1。 But I do not follow the correct paths when I make directions. 但是当我指示方向时,我没有遵循正确的路径。 I need to change the following lines of code to help you change the point, good day, good day app/Http/Controller/HomeController: 我需要更改以下代码行来帮助您更改要点,美好的一天,美好的一天app / Http / Controller / HomeController:

public function deneme($page){
        $url = url()->full();
        $myUrl = explode('/', $url);
        $uz= sizeof($myUrl);
        $myUrl = $myUrl[$uz-1];
        if ($myUrl == 'work.com'){
            $yazilar = YaziModel::join('users as u','u.id','=', 'yazilar.kullaniciid')->select('yazilar.*','u.name','u.created_at')->orderBy('yazilar.id', 'DESC')->get();

            $posts = array_slice($yazilar->getIterator()->getArrayCopy(),0,5);
            return view('backend.pages.anasayfa')->with('yazilar', $posts);
        }else{
            $baslangic = $page*5;
            $yazilar = YaziModel::join('users as u','u.id','=', 'yazilar.kullaniciid')->select('yazilar.*','u.name','u.created_at')->orderBy('yazilar.id', 'DESC')->get();

            $posts = array_slice($yazilar->getIterator()->getArrayCopy(),$baslangic,5);
            return view('backend.pages.anasayfa')->with('yazilar' ,$posts);
        }

    }


routes/web.php:

Route::get('/{page}', 'HomeController@deneme');

View : 查看:

<ul class="pager">
                    <li class="next">
                        <a href="{{url()->full()}}">Older Post &rarr;</a>
                    </li>
                </ul>

You can use this code in the blade (Laravel 5.7) 您可以在刀片中使用此代码(Laravel 5.7)

@if($news->previousPageUrl() != null)
    <a href="{{$news->previousPageUrl()}}" class="prev_btn pull-left"><i class="fa fa-chevron-left"></i> NEWER</a>
@endif

@if($news->nextPageUrl() != null)
    <a href="{{$news->nextPageUrl()}}" class="prev_btn pull-right">OLDER <i class="fa fa-chevron-right"></i> </a>
@endif

Use Pagination 使用分页

Controller 调节器

$users = DB::table('users')->paginate(15);

View 视图

{{ $users->links() }}

for More Details https://laravel.com/docs/5.2/pagination 了解更多信息https://laravel.com/docs/5.2/pagination

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM