1. Go to this page and download the library: Download weblabormx/world library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
weblabormx / world example snippets
use WeblaborMx\World\World;
// World::setApiBase("https://world.weblabor/api"); # Optionally set an alternative base
World::init(apiKey: "YOUR_API_KEY");
$client = World::getClient();
// Do stuff...
use WeblaborMx\World\Client;
$client = new Client(
apiKey: 'YOUR_API_KEY',
// apiBase: 'https://world.weblabor/api',
);
// Do stuff...
public function __construct(
public int $id,
public ?string $name = null,
public ?string $country = null,
public ?string $a1code = null,
public ?string $level = null,
public ?int $population = null,
public ?float $lat = null,
public ?float $long = null,
public ?string $timezone = null,
public ?int $parent_id = null,
) {
}
use WeblaborMx\World\World;
use WeblaborMx\World\Entities\Division;
$client = World::getClient();
/** @var Division[] **/
$countries = $client->makeCall('/countries');
foreach ($countries as $division) {
echo $division->name . \PHP_EOL;
}
use WeblaborMx\World\World;
use WeblaborMx\World\Entities\Division;
$client = World::getClient();
$code = "MX";
/** @var Division|null **/
$country = $client->makeCall("/country/{$code}");
use WeblaborMx\World\Entities\Division;
$id = 3531011; // Probably want to obtain it from the DB
/** @var Division|null **/
$division = Division::get($id);
use Illuminate\Database\Eloquent\Model;
use WeblaborMx\World\Casts\DivisionCast;
class Company extends Model
{
protected $casts = [
'country' => DivisionCast::class,
'state' => DivisionCast::class,
];
// ...
}
public function boot(): void
{
// World::setApiBase(config('services.weblabor.world.endpoint'));
World::init(apiKey: config('services.weblabor.world.token'));
}