1. Go to this page and download the library: Download rbaezc/hexagenphp-framework 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/ */
class Aerolinea extends Model
{
public function vuelos(): HasMany { return $this->hasMany(Vuelo::class, 'aerolinea_id'); }
public function pais(): BelongsTo { return $this->belongsTo(Pais::class); }
public function hub(): HasOne { return $this->hasOne(Aeropuerto::class); }
}
// Eager loading en exactamente 2 queries (sin N+1)
$aerolineas = Aerolinea::query()->with('vuelos', 'pais')->get();
// Eager loading con constraints
$aerolineas = Aerolinea::query()->with([
'vuelos' => fn($q) => $q->where('clase', 'business')->orderBy('precio')
])->get();
class Vuelo extends Model
{
use HasTimestamps; // created_at / updated_at automáticos
use SoftDeletes; // deleted_at — no borra físicamente
use HasCasts; // cast automático de tipos
use HasScopes; // scopes locales y globales
use HasObservers; // hooks created/updated/deleted
use HasFactory; // Vuelo::factory()->create()
protected static array $fillable = ['origen', 'destino', 'precio', 'clase'];
protected static array $casts = ['precio' => 'float', 'activo' => 'bool'];
}
// database/migrations/2024_01_01_create_vuelos_table.php
return new class extends Migration {
public function up(\PDO $pdo): void {
$pdo->exec("CREATE TABLE vuelos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
origen VARCHAR(3) NOT NULL,
destino VARCHAR(3) NOT NULL,
precio DECIMAL(10,2),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)");
}
public function down(\PDO $pdo): void {
$pdo->exec("DROP TABLE IF EXISTS vuelos");
}
};
class ContadorVuelos extends LiveComponent
{
public int $clicks = 0;
public function incrementar(): void { $this->clicks++; }
public function render(): string { return $this->renderView('@Vuelos/contador.twig'); }
}
// public/index.php
$kernel = new HexaGen\Core\Kernel();
$kernel->boot();
if (function_exists('frankenphp_handle_request')) {
for ($i = 0; frankenphp_handle_request() && $i < 1000; ++$i) {
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response); // limpia auth + request por request
gc_collect_cycles();
}
}