53 lines
1.3 KiB
PHP
53 lines
1.3 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 getLogoById(int $id){
|
|
$airline = Airline::where('id', $id)
|
|
->first();
|
|
|
|
return $this->getAirlineLogo($airline);
|
|
}
|
|
|
|
public function getLogoByCode(string $code){
|
|
|
|
$column = strlen($code) == 2
|
|
? 'IATA_code'
|
|
: 'ICAO_code';
|
|
|
|
$airline = Airline::where($column, strtoupper($code))
|
|
->whereNotNull('logo')
|
|
->where('active', true)
|
|
->latest('id')
|
|
->first();
|
|
|
|
if (!$airline) {
|
|
$airline = Airline::where($column, strtoupper($code))
|
|
->whereNotNull('logo')
|
|
->latest('id')
|
|
->first();
|
|
}
|
|
|
|
return $this->getAirlineLogo($airline);
|
|
}
|
|
}
|