Now I have some problem that is to paginate all data stored in my Tasks table, I have trying some code in ways to make pagination in laravel, but the code not work with .vue file extension. I'm using laravel 5.8, vue.js, axios, and vue-router-view.
My code not working or its maybe wrong overall,
// this is my index function in my taskController file :
public function index(Request $request)
{
// return new taskCollection(Task::orderBy('created_at', 'desc')->paginate(5));
$tasks = Task::orderBy('created_at', 'desc')->paginate(10);
return response()->json($tasks)
->withCallback($request->callback);
}
// and this is my code to fetch the data from response given by controller:
methods: {
getTaskList() {
let uri = `/api/tasks`;
this.axios
.get(uri)
.then(response => {
if (!this.tasks.data) {
this.tasks = response.data.data;
} else {
this.tasks.data.push(...response.data.data);
this.tasks.next_page_url = response.data.next_page_url;
}
})
.catch(function(error) {
console.log(error);
});
},
//I want to paginate the data so it's not showing all data entire the page.
this.tasks = response.data;
– Boussadjra Brahim