Skip to content

Members Request

Ben Sherred edited this page Nov 5, 2021 · 10 revisions

Introduction

A company can have multiple members and you can these members by using the examples shown below. If you want to get a specific member, check out the Member Request page.

Getting Members

To get the members for a company, you can call the members() method on the CompanyRequest. This will return an instance of CompanyMemberIndex.

<?php

require_once('vendor/autoload.php');

$client = new TruckersMP\APIClient();
$members = $client->company(1)->members()->get(); // This is instance of `CompanyMemberIndex`

Available Methods

The CompanyMemberIndex class has a couple of methods to get additional information about the company members.

Method Listing

getMembers()

The getMembers method returns an instance of MemberCollection which is an array of CompanyMember models. Below is an example of how you might get the names of all the members in the company.

$names = [];
$members = $client->company(1)->members()->get();

foreach ($members->getMembers() as $member) {
    array_put($names, $member->getName());
}

echo implode(', ', $names);

getCount()

The getCount method returns the number members in the company.

$members = $client->company(1)->members()->get();
$count = $members->getCount();

echo "There are {$count} members in this company.";