Based on your requirements as listed, I would suggest the following - Laravel specific - approach:
- "It contains Fleets, Wings, and Squadrons."
Sounds to me like three separate models, each having their own database table.
- "A Fleet, may/may not have wings, a fleet may have squads."
Take a look at Laravel's relation ships. Jeffrey also has a nice series on this topic here at Laracasts: https://laracasts.com/series/eloquent-relationships/episodes/1.
- "Squads must belong to either a fleet or a wing."
This calls for a polymorphic relationship.
- "Wings are optional. all three units (Fleet, Wing, Squadron) share some common factors: ID, Name, Title, Description, CO, XO, SO"
Just add them to the appropriate database migrations for the Fleet, Wing and Squadron tables, for example:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateWingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wings', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('title');
$table->text('description');
$table->unsignedInteger('CO');
$table->unsignedInteger('XO');
$table->unsignedInteger('SO');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('wings');
}
}
For the CO, XO and SO references, you'll need to implement the appropriate relationship.
- [...] and a squad will have a number of slots for total users.
I don't know exactly what your implementation will be for "slots for total users", but I guess you can rely on a many-to-many relationship between Users and Squadrons. Check out the many-to-many relationship which requires a pivot-table.
// Squadron.php
public function users()
{
return $this->belongsToMany(User::class);
}
I hope I could have helped you somewhat, otherwise let me know.