Laravel 5 - Manual pagination










11















Pagination::make() method doesn't exist in Pagination class anymore in Laravel 5.



Is there a workaround to make manual pagination work in Laravel 5?










share|improve this question




























    11















    Pagination::make() method doesn't exist in Pagination class anymore in Laravel 5.



    Is there a workaround to make manual pagination work in Laravel 5?










    share|improve this question


























      11












      11








      11


      4






      Pagination::make() method doesn't exist in Pagination class anymore in Laravel 5.



      Is there a workaround to make manual pagination work in Laravel 5?










      share|improve this question
















      Pagination::make() method doesn't exist in Pagination class anymore in Laravel 5.



      Is there a workaround to make manual pagination work in Laravel 5?







      laravel pagination laravel-5 laravel-pagination






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 18 '14 at 12:36









      Marcin Nabiałek

      72.4k28151188




      72.4k28151188










      asked Nov 30 '14 at 12:54









      aBhijitaBhijit

      1,82562951




      1,82562951






















          5 Answers
          5






          active

          oldest

          votes


















          26














          You need to add use:



          use IlluminatePaginationLengthAwarePaginator as Paginator;


          and now you can use:



           $paginator = new Paginator($items, $count, $limit, $page, [
          'path' => $this->request->url(),
          'query' => $this->request->query(),
          ]);


          to get data in the same format as paginating on model object;






          share|improve this answer


















          • 1





            Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

            – JCarlos
            Aug 6 '16 at 16:38











          • Could you explain parameters please?

            – SaidbakR
            Jun 1 '17 at 20:18











          • The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

            – SaidbakR
            Jun 1 '17 at 20:53












          • how to render pages on the blade frontend then? thanks

            – JahStation
            Mar 16 '18 at 14:46


















          1














          You can create manual pagination like this



          $data = DB::table('post')->skip(0)->take(20)->get();






          share|improve this answer
































            1














            Pretty way to instance this class



             use IlluminatePaginationLengthAwarePaginator as Paginator;
            //...
            $paginator = new Paginator($items->forPage($page, $limit), $count, $limit, $page, [
            'path' => Paginator::resolveCurrentPath()
            ]);


            Note items must be a Collection Object.






            share|improve this answer






























              0














              Try below code for manual pagination



              <?php

              namespace AppHttpControllers;

              use IlluminatePaginationLengthAwarePaginator as Paginator;
              // use IlluminatePaginationPaginator;
              use IlluminateHttpRequest;
              use AppProduct;
              class MyController extends Controller

              public function index(Request $request)
              $items = Product::all();

              $filter_products = ; // Manual filter or your array for pagination

              foreach($items as $item)
              if($item['id']>40 && $item['id']<50)
              array_push($filter_products, $item);



              $count = count($filter_products); // total product for pagination
              $page = $request->page; // current page for pagination

              // manually slice array of product to display on page
              $perPage = 5;
              $offset = ($page-1) * $perPage;
              $products = array_slice($filter_products, $offset, $perPage);

              // your pagination
              $products = new Paginator($products, $count, $perPage, $page, ['path' => $request->url(),'query' => $request->query(),]);
              // use $products->appends($_GET)->links() to dispaly your pagination
              return view('index',['products' => $products]);







              share|improve this answer




















              • 5





                Add some explanation to your answer . Code only answer are not really useful.

                – ADM
                Apr 20 '18 at 14:27


















              -5














              Another way of using pagination would be like this:



              public function index()

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






              share|improve this answer
























                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27213453%2flaravel-5-manual-pagination%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                26














                You need to add use:



                use IlluminatePaginationLengthAwarePaginator as Paginator;


                and now you can use:



                 $paginator = new Paginator($items, $count, $limit, $page, [
                'path' => $this->request->url(),
                'query' => $this->request->query(),
                ]);


                to get data in the same format as paginating on model object;






                share|improve this answer


















                • 1





                  Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                  – JCarlos
                  Aug 6 '16 at 16:38











                • Could you explain parameters please?

                  – SaidbakR
                  Jun 1 '17 at 20:18











                • The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                  – SaidbakR
                  Jun 1 '17 at 20:53












                • how to render pages on the blade frontend then? thanks

                  – JahStation
                  Mar 16 '18 at 14:46















                26














                You need to add use:



                use IlluminatePaginationLengthAwarePaginator as Paginator;


                and now you can use:



                 $paginator = new Paginator($items, $count, $limit, $page, [
                'path' => $this->request->url(),
                'query' => $this->request->query(),
                ]);


                to get data in the same format as paginating on model object;






                share|improve this answer


















                • 1





                  Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                  – JCarlos
                  Aug 6 '16 at 16:38











                • Could you explain parameters please?

                  – SaidbakR
                  Jun 1 '17 at 20:18











                • The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                  – SaidbakR
                  Jun 1 '17 at 20:53












                • how to render pages on the blade frontend then? thanks

                  – JahStation
                  Mar 16 '18 at 14:46













                26












                26








                26







                You need to add use:



                use IlluminatePaginationLengthAwarePaginator as Paginator;


                and now you can use:



                 $paginator = new Paginator($items, $count, $limit, $page, [
                'path' => $this->request->url(),
                'query' => $this->request->query(),
                ]);


                to get data in the same format as paginating on model object;






                share|improve this answer













                You need to add use:



                use IlluminatePaginationLengthAwarePaginator as Paginator;


                and now you can use:



                 $paginator = new Paginator($items, $count, $limit, $page, [
                'path' => $this->request->url(),
                'query' => $this->request->query(),
                ]);


                to get data in the same format as paginating on model object;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 18 '14 at 12:37









                Marcin NabiałekMarcin Nabiałek

                72.4k28151188




                72.4k28151188







                • 1





                  Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                  – JCarlos
                  Aug 6 '16 at 16:38











                • Could you explain parameters please?

                  – SaidbakR
                  Jun 1 '17 at 20:18











                • The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                  – SaidbakR
                  Jun 1 '17 at 20:53












                • how to render pages on the blade frontend then? thanks

                  – JahStation
                  Mar 16 '18 at 14:46












                • 1





                  Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                  – JCarlos
                  Aug 6 '16 at 16:38











                • Could you explain parameters please?

                  – SaidbakR
                  Jun 1 '17 at 20:18











                • The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                  – SaidbakR
                  Jun 1 '17 at 20:53












                • how to render pages on the blade frontend then? thanks

                  – JahStation
                  Mar 16 '18 at 14:46







                1




                1





                Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                – JCarlos
                Aug 6 '16 at 16:38





                Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator.

                – JCarlos
                Aug 6 '16 at 16:38













                Could you explain parameters please?

                – SaidbakR
                Jun 1 '17 at 20:18





                Could you explain parameters please?

                – SaidbakR
                Jun 1 '17 at 20:18













                The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                – SaidbakR
                Jun 1 '17 at 20:53






                The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…

                – SaidbakR
                Jun 1 '17 at 20:53














                how to render pages on the blade frontend then? thanks

                – JahStation
                Mar 16 '18 at 14:46





                how to render pages on the blade frontend then? thanks

                – JahStation
                Mar 16 '18 at 14:46













                1














                You can create manual pagination like this



                $data = DB::table('post')->skip(0)->take(20)->get();






                share|improve this answer





























                  1














                  You can create manual pagination like this



                  $data = DB::table('post')->skip(0)->take(20)->get();






                  share|improve this answer



























                    1












                    1








                    1







                    You can create manual pagination like this



                    $data = DB::table('post')->skip(0)->take(20)->get();






                    share|improve this answer















                    You can create manual pagination like this



                    $data = DB::table('post')->skip(0)->take(20)->get();







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 20 '16 at 8:06









                    CinCout

                    5,27183541




                    5,27183541










                    answered Dec 20 '16 at 8:00









                    Naresh SumanNaresh Suman

                    194




                    194





















                        1














                        Pretty way to instance this class



                         use IlluminatePaginationLengthAwarePaginator as Paginator;
                        //...
                        $paginator = new Paginator($items->forPage($page, $limit), $count, $limit, $page, [
                        'path' => Paginator::resolveCurrentPath()
                        ]);


                        Note items must be a Collection Object.






                        share|improve this answer



























                          1














                          Pretty way to instance this class



                           use IlluminatePaginationLengthAwarePaginator as Paginator;
                          //...
                          $paginator = new Paginator($items->forPage($page, $limit), $count, $limit, $page, [
                          'path' => Paginator::resolveCurrentPath()
                          ]);


                          Note items must be a Collection Object.






                          share|improve this answer

























                            1












                            1








                            1







                            Pretty way to instance this class



                             use IlluminatePaginationLengthAwarePaginator as Paginator;
                            //...
                            $paginator = new Paginator($items->forPage($page, $limit), $count, $limit, $page, [
                            'path' => Paginator::resolveCurrentPath()
                            ]);


                            Note items must be a Collection Object.






                            share|improve this answer













                            Pretty way to instance this class



                             use IlluminatePaginationLengthAwarePaginator as Paginator;
                            //...
                            $paginator = new Paginator($items->forPage($page, $limit), $count, $limit, $page, [
                            'path' => Paginator::resolveCurrentPath()
                            ]);


                            Note items must be a Collection Object.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 13 '18 at 19:12









                            GomsGoms

                            664721




                            664721





















                                0














                                Try below code for manual pagination



                                <?php

                                namespace AppHttpControllers;

                                use IlluminatePaginationLengthAwarePaginator as Paginator;
                                // use IlluminatePaginationPaginator;
                                use IlluminateHttpRequest;
                                use AppProduct;
                                class MyController extends Controller

                                public function index(Request $request)
                                $items = Product::all();

                                $filter_products = ; // Manual filter or your array for pagination

                                foreach($items as $item)
                                if($item['id']>40 && $item['id']<50)
                                array_push($filter_products, $item);



                                $count = count($filter_products); // total product for pagination
                                $page = $request->page; // current page for pagination

                                // manually slice array of product to display on page
                                $perPage = 5;
                                $offset = ($page-1) * $perPage;
                                $products = array_slice($filter_products, $offset, $perPage);

                                // your pagination
                                $products = new Paginator($products, $count, $perPage, $page, ['path' => $request->url(),'query' => $request->query(),]);
                                // use $products->appends($_GET)->links() to dispaly your pagination
                                return view('index',['products' => $products]);







                                share|improve this answer




















                                • 5





                                  Add some explanation to your answer . Code only answer are not really useful.

                                  – ADM
                                  Apr 20 '18 at 14:27















                                0














                                Try below code for manual pagination



                                <?php

                                namespace AppHttpControllers;

                                use IlluminatePaginationLengthAwarePaginator as Paginator;
                                // use IlluminatePaginationPaginator;
                                use IlluminateHttpRequest;
                                use AppProduct;
                                class MyController extends Controller

                                public function index(Request $request)
                                $items = Product::all();

                                $filter_products = ; // Manual filter or your array for pagination

                                foreach($items as $item)
                                if($item['id']>40 && $item['id']<50)
                                array_push($filter_products, $item);



                                $count = count($filter_products); // total product for pagination
                                $page = $request->page; // current page for pagination

                                // manually slice array of product to display on page
                                $perPage = 5;
                                $offset = ($page-1) * $perPage;
                                $products = array_slice($filter_products, $offset, $perPage);

                                // your pagination
                                $products = new Paginator($products, $count, $perPage, $page, ['path' => $request->url(),'query' => $request->query(),]);
                                // use $products->appends($_GET)->links() to dispaly your pagination
                                return view('index',['products' => $products]);







                                share|improve this answer




















                                • 5





                                  Add some explanation to your answer . Code only answer are not really useful.

                                  – ADM
                                  Apr 20 '18 at 14:27













                                0












                                0








                                0







                                Try below code for manual pagination



                                <?php

                                namespace AppHttpControllers;

                                use IlluminatePaginationLengthAwarePaginator as Paginator;
                                // use IlluminatePaginationPaginator;
                                use IlluminateHttpRequest;
                                use AppProduct;
                                class MyController extends Controller

                                public function index(Request $request)
                                $items = Product::all();

                                $filter_products = ; // Manual filter or your array for pagination

                                foreach($items as $item)
                                if($item['id']>40 && $item['id']<50)
                                array_push($filter_products, $item);



                                $count = count($filter_products); // total product for pagination
                                $page = $request->page; // current page for pagination

                                // manually slice array of product to display on page
                                $perPage = 5;
                                $offset = ($page-1) * $perPage;
                                $products = array_slice($filter_products, $offset, $perPage);

                                // your pagination
                                $products = new Paginator($products, $count, $perPage, $page, ['path' => $request->url(),'query' => $request->query(),]);
                                // use $products->appends($_GET)->links() to dispaly your pagination
                                return view('index',['products' => $products]);







                                share|improve this answer















                                Try below code for manual pagination



                                <?php

                                namespace AppHttpControllers;

                                use IlluminatePaginationLengthAwarePaginator as Paginator;
                                // use IlluminatePaginationPaginator;
                                use IlluminateHttpRequest;
                                use AppProduct;
                                class MyController extends Controller

                                public function index(Request $request)
                                $items = Product::all();

                                $filter_products = ; // Manual filter or your array for pagination

                                foreach($items as $item)
                                if($item['id']>40 && $item['id']<50)
                                array_push($filter_products, $item);



                                $count = count($filter_products); // total product for pagination
                                $page = $request->page; // current page for pagination

                                // manually slice array of product to display on page
                                $perPage = 5;
                                $offset = ($page-1) * $perPage;
                                $products = array_slice($filter_products, $offset, $perPage);

                                // your pagination
                                $products = new Paginator($products, $count, $perPage, $page, ['path' => $request->url(),'query' => $request->query(),]);
                                // use $products->appends($_GET)->links() to dispaly your pagination
                                return view('index',['products' => $products]);








                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 15 '18 at 5:36

























                                answered Apr 20 '18 at 12:57









                                SangeetSangeet

                                113




                                113







                                • 5





                                  Add some explanation to your answer . Code only answer are not really useful.

                                  – ADM
                                  Apr 20 '18 at 14:27












                                • 5





                                  Add some explanation to your answer . Code only answer are not really useful.

                                  – ADM
                                  Apr 20 '18 at 14:27







                                5




                                5





                                Add some explanation to your answer . Code only answer are not really useful.

                                – ADM
                                Apr 20 '18 at 14:27





                                Add some explanation to your answer . Code only answer are not really useful.

                                – ADM
                                Apr 20 '18 at 14:27











                                -5














                                Another way of using pagination would be like this:



                                public function index()

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






                                share|improve this answer





























                                  -5














                                  Another way of using pagination would be like this:



                                  public function index()

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






                                  share|improve this answer



























                                    -5












                                    -5








                                    -5







                                    Another way of using pagination would be like this:



                                    public function index()

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






                                    share|improve this answer















                                    Another way of using pagination would be like this:



                                    public function index()

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







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 10 '16 at 9:44









                                    Vojtech Ruzicka

                                    8,995154449




                                    8,995154449










                                    answered Nov 10 '16 at 4:12









                                    n31ln31l

                                    6519




                                    6519



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27213453%2flaravel-5-manual-pagination%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Top Tejano songwriter Luis Silva dead of heart attack at 64

                                        ReactJS Fetched API data displays live - need Data displayed static

                                        Evgeni Malkin