0👍
✅
Finally solved it by returning four variables instead of one.
public function index()
{
$this->authorize('isAdmin');
$admin = User::where('user_type','admin')->selectRaw('count(user_type) as admin')->get()->toArray();
$surveyor = User::where('user_type','surveyor')->selectRaw('count(user_type) as surveyor')->get()->toArray();
$normaluser = User::where('user_type','user')->selectRaw('count(user_type) as normaluser')->get()->toArray();
$user = User::latest()->paginate(5);
return response()->json([$admin,$surveyor,$normaluser,$user]);
}
And got the response in vue by direct accessing of arrays
methods: {
getResults(page = 1) {
this.$Progress.start();
axios.get('api/user?page=' + page)
.then(response => {
this.users = response.data;
this.admins = this.users[0][0].admin;
this.surveyors = this.users[1][0].surveyor;
this.standard_users = this.users[2][0].normaluser;
});
axios.get('api/form-one')
.then(response => {
this.lists = response.data;
this.forms = this.lists[0][0].form;
console.log(this.forms);
});
this.$Progress.finish();
},
},
May not be best way to do that but this is exactly what I was looking for.
0👍
Pagination does in fact return a total count.
It is accessible via: rsp.data.total
where as your data is stored in rsp.data.data
.
Below is a sample response from the paginate(50)
function.
current_page: 1
data: [mydatahere]
first_page_url: "https://someurl.com/items?page=1"
from: 1
last_page: 2
last_page_url: "https://someurl.com/items?page=2"
next_page_url: "https://someurl.com/items?page=2"
path: "https://someurl.com/items"
per_page: 50
prev_page_url: null
to: 50
total: 92
Source:stackexchange.com