Files
FlightsAPI/app/Http/Controllers/LogoController.php
T
2026-04-01 14:27:06 +10:00

51 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Airline;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class LogoController extends Controller
{
public function getAirlineLogo(?Airline $airline){
$logoFile = $airline?->logo ?? 'blank.png';
$path = 'images/logos/tail/' . $logoFile;
if (!Storage::disk('local')->exists($path)) {
$path = 'images/logos/tail/blank.png';
}
return response()->file(Storage::disk('local')->path($path), [
'Content-Type' => 'image/png',
]);
}
public function getLogoByIATACode(string $code)
{
$airline = Airline::where('IATA_code', strtoupper($code))
->whereNotNull('logo')
->latest('id')
->first();
return $this->getAirlineLogo($airline);
}
public function getLogoByICAOCode(string $code)
{
$airline = Airline::where('ICAO_code', strtoupper($code))
->whereNotNull('logo')
->latest('id')
->first();
return $this->getAirlineLogo($airline);
}
public function getLogoByCode(string $code){
return strlen($code) == 2
? $this->getLogoByIATACode($code)
: $this->getLogoByICAOCode($code);
}
}