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