PHP code example of maxiewright / ttdf-orbat

1. Go to this page and download the library: Download maxiewright/ttdf-orbat 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/ */

    

maxiewright / ttdf-orbat example snippets


use MaxieWright\TtdfOrbat\Facades\TtdfOrbat;

// All active formations
TtdfOrbat::formations();

// Single formation by abbreviation
TtdfOrbat::formation('TTR');

// Ranks for a formation (ordered by seniority)
TtdfOrbat::ranks('TTR');

// Filter by category
TtdfOrbat::officers('TTCG');
TtdfOrbat::otherRanks('TTAG');

// All rank grades (cross-service equivalence table)
TtdfOrbat::grades();

// Unit tree (top-level units with children eager-loaded)
TtdfOrbat::tree('TTR');

// All active units for a formation (flat)
TtdfOrbat::units('TTR');

// Appointments for a unit (by abbreviation or model)
TtdfOrbat::appointments('1TTR');
TtdfOrbat::commandAppointments('1TTR');

// Data version
TtdfOrbat::version(); // "0.1.0"

$battalion = Unit::where('abbreviation', '1TTR')->first();

// Full subtree
$battalion->descendants;

// Ancestors to root
$platoon->ancestors;

// Breadcrumb string: "RHQ > 1TTR > A COY > 1 PL"
$platoon->breadcrumb;

// Effective parent (respects active attachments for detachments)
$detachment->effectiveParent;

use MaxieWright\TtdfOrbat\Models\Unit;

$battalion = Unit::where('abbreviation', '1TTR')->first();

// All appointments for this unit
$battalion->appointments;

// Via facade (cached, eager-loads rank grades)
TtdfOrbat::appointments('1TTR');

// Command appointments only (CO, OC, Pl Comd, etc.)
TtdfOrbat::commandAppointments($battalion);

// Accessors
$appointment->full_title;  // "CO (Commanding Officer)"
$appointment->rank_range;  // "OF-3 – OF-4"

use MaxieWright\TtdfOrbat\Models\Formation;
use MaxieWright\TtdfOrbat\Models\Unit;
use MaxieWright\TtdfOrbat\Models\Rank;
use MaxieWright\TtdfOrbat\Models\RankGrade;
use MaxieWright\TtdfOrbat\Models\UnitDetail;
use MaxieWright\TtdfOrbat\Models\UnitAttachment;

// Create a formation
$formation = Formation::factory()->regiment()->create();

// Build a unit tree
$bn = Unit::factory()->battalion()->create(['formation_id' => $formation->id]);
$coy = Unit::factory()->company()->childOf($bn)->create();
$plt = Unit::factory()->platoon()->childOf($coy)->create();

// Vessel with details
$vessel = Unit::factory()->vessel()->create(['formation_id' => $formation->id]);
$detail = UnitDetail::factory()->forVessel($vessel)->create();

// Base with coordinates
$base = Unit::factory()->headquarters()->create(['formation_id' => $formation->id]);
$detail = UnitDetail::factory()->forBase($base)->create();

// Rank with grade
$grade = RankGrade::factory()->officer()->create();
$rank = Rank::factory()->create([
    'rank_grade_id' => $grade->id,
    'formation_id' => $formation->id,
]);

// Attachment (current and historical)
$attachment = UnitAttachment::factory()->create([
    'unit_id' => $plt->id,
    'attached_to_id' => $bn->id,
]);
$ended = UnitAttachment::factory()->ended()->create();

// Appointment
use MaxieWright\TtdfOrbat\Models\Appointment;

$co = Appointment::factory()->command()->create([
    'unit_id' => $bn->id,
    'title' => 'Commanding Officer',
    'abbreviation' => 'CO',
]);
bash
php artisan vendor:publish --tag="ttdf-orbat-migrations"
php artisan migrate
bash
php artisan ttdf-orbat:seed
bash
# Config
php artisan vendor:publish --tag="ttdf-orbat-config"

# Seeders (to customise or extend)
php artisan vendor:publish --tag="ttdf-orbat-seeders"

# Model factories (for testing in your application)
php artisan vendor:publish --tag="ttdf-orbat-factories"
bash
php artisan vendor:publish --tag="ttdf-orbat-factories"