phpvms/app/Models/Observers/AirportObserver.php
2018-08-26 16:40:04 +00:00

38 lines
798 B
PHP

<?php
namespace App\Models\Observers;
use App\Models\Airport;
/**
* Make sure that the fields are properly capitalized
*/
class AirportObserver
{
/**
* @param Airport $airport
*/
public function creating(Airport $airport): void
{
if (filled($airport->iata)) {
$airport->iata = strtoupper(trim($airport->iata));
}
$airport->icao = strtoupper(trim($airport->icao));
$airport->id = $airport->icao;
}
/**
* @param Airport $airport
*/
public function updating(Airport $airport): void
{
if (filled($airport->iata)) {
$airport->iata = strtoupper(trim($airport->iata));
}
$airport->icao = strtoupper(trim($airport->icao));
$airport->id = $airport->icao;
}
}