Skip to content

Bans Request

Ben Sherred edited this page Dec 3, 2019 · 3 revisions

In order to get the bans for a player, you can call the bans() method on the Client instance. This method takes 1 parameter which can either be the players SteamID64 or TruckersMP ID like so:

SteamID64

<?php

require_once('vendor/autoload.php');

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

$player = $client->bans('76561198154335536')->get();

TruckersMP ID

<?php

require_once('vendor/autoload.php');

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

$player = $client->bans(28159)->get();

This will return an instance of BanCollection.

The Collection

The BanCollection returns an array of Ban models. You can loop through the bans like so:

<?php

require_once('vendor/autoload.php');

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

foreach ($bans as $ban) {
    // $ban is an instance of a `Ban` model
}

The Model

To get the data from the model, a number of helpful getters have been created as shown below.

Method Type Description
getExpirationDate() ?Carbon The time that the ban will expire (UTC) or null if permanent
getCreatedAt() Carbon The players username
isActive() bool If the ban is still active [1]
getReason() string The reason the user was banned
getAdminName() string The name of the admin who banned the user)
getAdminId() int The TruckersMP ID of the admin that banned the user

[1] For the player to be banned the expiration date has to either be passed or isActive() has to be false.

Example

Below is an example of how you would get the reason for each ban:

<?php

require_once('vendor/autoload.php');

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

foreach ($bans as $ban) {
    $reason = $ban->getReason();
}