Skip to content

Companies Request

Ben Sherred edited this page Dec 7, 2019 · 2 revisions

To get the most recent and featured companies, you can call the companies() method on the Client instance like so:

<?php

require_once('vendor/autoload.php');

$client = new TruckersMP\APIClient\Client();

$companies = $client->companies()->get();

This will return an instance of the CompanyIndex model.

The Model

The model has a few helpful getters to get the recent and featured companies.

Method Type Description
getRecent() CompanyCollection The recent companies that have been created
getFeatured() CompanyCollection The featured companies
getFeaturedCovered() CompanyCollection The companies featured on the VTC cover page

The Collection

Each getter returns an instance of CompanyCollection. You can loop through the collection, as shown below, which will return an instance of the Company model. For more information on this model, please refer to the Company Request page.

Example

Below is an example of how you would loop through the collection.

<?php

require_once('vendor/autoload.php');

$client = new TruckersMP\APIClient\Client();
$companies= $client->companies()->get();

foreach ($companies->getRecent() as $company) {
    // $company is an instance of the `Company` model
}