vendredi 31 mars 2017

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. 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. 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:

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);
        }

    }

Routers/web.php:

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

View :

<ul class="pager">
                    <li class="next">
                        <a href="">Older Post &rarr;</a>
                    </li>
                </ul>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire