Seif5's avatar

Angular/Laravel pagination api

Hello ,I am new with angularJS/laravel , so I succed to get all my api resource with laravel and angularJS. but I still want to make a pagination to the api.

0 likes
10 replies
d3xt3r's avatar

If your are sending a paginated response, you have everything (all details) in there, whats bothering you ?

Seif5's avatar

@d3xt3r No :o myController resource

    public function index(Request $request)
    {
           $questions = Question::all();
           return $questions;

    }

    public function show($id)
    {
           $questions = Question::all();
           return $questions;
    }
d3xt3r's avatar

@Amelie89 Don't be judgemental, its Saturday after all. you need to use paginate() in order to get the paginated response, then you can create components in angular to handle it.

Example:

public function index(Request $request)
    {
           $questions = Question::paginate(15); // or whatever you like
           return $questions;

    }
Seif5's avatar

@d3xt3r thankyou for your answer , I already tried that but it didn't work , ( I can see the data on the console but no data displayed on the browser)

d3xt3r's avatar

You will have to modify your angular scripts, with pagination the actual data is contained within data object ...

Seif5's avatar

@bobbybouwmann @d3xt3r dosen't work for me


var app = angular.module('app', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});

app.controller('questionController', function($scope, $http) {


    $scope.questions = [];
    $scope.historiques = [];
    $scope.loading = false;

    $scope.init = function() {
        $scope.loading = true;
        $http.get('/api/v1/questions').
        success(function(data, status, headers, config) {
            $scope.questions = data;
            $scope.loading = false;

        });
    }



    


    $scope.init();

});

what code should be added on the angular file script

Please or to participate in this conversation.