I have just started my journey with Laravel and PHP.
I have this route:
Route::get('/admin/applications/staff-role', function () {
$staff = StaffRole::with('applications')->where('id', '=', '1')->get();
return $staff;
});
which is the result of hasManyThrough query and returns this result:
[
{
"id": 1,
"staff_role_label": "Staff 1",
"staff_role_description": "Staff Role 1",
"staff_role_abbreviation": "SR1",
"deleted_at": null,
"applications": [
{
"id": 1,
"vacancy_id": 1,
"hours_per_week": "9",
"contract_type": "Full-Time",
"desired_shift_option": "Weekends",
"name": "John",
"surname": "Doe",
"mobile_phone_number": "07911 123456",
"email": "test1@test.com",
"application_status": 1,
"is_staff": 1,
"staff_status": 0,
"deleted_at": null,
"laravel_through_key": 1
},
{
"id": 2,
"vacancy_id": 1,
"hours_per_week": "9",
"contract_type": "Full-Time",
"desired_shift_option": "Weekends",
"name": "Jane",
"surname": "Doe",
"mobile_phone_number": "07911 123456",
"email": "test2@test.com",
"application_status": 1,
"is_staff": 1,
"staff_status": 0,
"deleted_at": null,
"laravel_through_key": 1
}
]
}
]
So far, so good, but how can I count how many applications I have in the array?
Thanks.