phpvms/app/Repositories/AirportRepository.php

50 lines
1005 B
PHP
Raw Normal View History

<?php
namespace App\Repositories;
use App\Models\Airport;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
2017-08-25 02:03:10 +08:00
class AirportRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
protected $fieldSearchable = [
2018-01-04 10:07:34 +08:00
'icao' => 'like',
'name' => 'like',
];
public function model()
{
return Airport::class;
}
/**
* Return the list of airports formatted for a select box
* @return array
*/
public function selectBoxList($add_blank=false, $only_hubs=false): array
{
$retval = [];
$where = [];
if($only_hubs) {
$where['hub'] = 1;
}
$items = $this->orderBy('icao', 'asc')->findWhere($where);
if ($add_blank) {
$retval[''] = '';
}
foreach ($items as $i) {
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
}
return $retval;
}
}