Skip to content

Posts Request

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

Introduction

You can get all the posts for a company by executing the following code.

Getting Posts

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

<?php

require_once('vendor/autoload.php');

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

You can then loop through the posts to get information about a specific post. For more information, check out the available methods on the Post Request page.

$posts = $client->company(1)->posts()->get();

$count = 0;
foreach ($posts as $post) {
    $count++;
}

echo "This company has {$count} posts";