Here is the code snippet for my ajax request:
<script>
new Vue({
...
methods: {
fetchItems: function (page) {
var data = {page: page};
this.$http.get('api/items', data).then(function (response) {
console.log(JSON.stringify(response))
this.$set(this, 'items', response.data.data.data);
this.$set(this, 'pagination', response.data.pagination);
}, function (error) {
// handle error
});
},
...
}
});
</script>
My routes for the API are defined as follows:
Route::get('/api/items/', function () {
dd(Input::get('page'));
$results = \App\Post::latest()->paginate(7);
$response = [
'pagination' => [
'total' => $results->total(),
'per_page' => $results->perPage(),
'current_page' => $results->currentPage(),
'last_page' => $results->lastPage(),
'from' => $results->firstItem(),
'to' => $results->lastItem()
],
'data' => $results
];
return $response;
});
After execution, when I check the console, the result is null, even though I have included dd(Input::get('page'));
It should display the page that was sent.
How can I resolve this issue?