2017-06-18 06:25:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Models\Flight;
|
2017-12-05 00:59:25 +08:00
|
|
|
use App\Repositories\Criteria\WhereCriteria;
|
2017-12-07 12:48:42 +08:00
|
|
|
use App\Repositories\Traits\CacheableRepository;
|
2017-12-05 02:05:31 +08:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2017-12-05 00:59:25 +08:00
|
|
|
use Illuminate\Http\Request;
|
2017-12-01 10:28:45 +08:00
|
|
|
use Prettus\Repository\Contracts\CacheableInterface;
|
2017-06-18 06:25:36 +08:00
|
|
|
|
2017-12-01 10:28:45 +08:00
|
|
|
class FlightRepository extends BaseRepository implements CacheableInterface
|
2017-06-18 06:25:36 +08:00
|
|
|
{
|
2017-12-01 10:28:45 +08:00
|
|
|
use CacheableRepository;
|
|
|
|
|
2017-06-18 06:25:36 +08:00
|
|
|
protected $fieldSearchable = [
|
2017-12-01 10:28:45 +08:00
|
|
|
'arr_airport_id',
|
2017-06-18 06:25:36 +08:00
|
|
|
'dpt_airport_id',
|
2017-12-01 10:28:45 +08:00
|
|
|
'flight_number' => 'like',
|
|
|
|
'route' => 'like',
|
|
|
|
'notes' => 'like',
|
2017-06-18 06:25:36 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Flight::class;
|
|
|
|
}
|
2017-12-05 00:59:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the search criteria and return this with the stuff pushed
|
2017-12-05 02:05:31 +08:00
|
|
|
* @param FormRequest $request
|
2017-12-05 00:59:25 +08:00
|
|
|
* @param bool $only_active
|
|
|
|
* @return $this
|
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
|
|
|
*/
|
|
|
|
public function searchCriteria(Request $request, bool $only_active=true)
|
|
|
|
{
|
|
|
|
$where = [
|
|
|
|
'active' => $only_active,
|
|
|
|
];
|
|
|
|
|
2017-12-05 02:05:31 +08:00
|
|
|
if ($request->filled('airline_id')) {
|
|
|
|
$where['airline_id'] = $request->airline_id;
|
2017-12-05 00:59:25 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 02:05:31 +08:00
|
|
|
if($request->filled('flight_number')) {
|
|
|
|
$where['flight_number'] = $request->flight_number;
|
2017-12-05 00:59:25 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 02:05:31 +08:00
|
|
|
if ($request->filled('route_code')) {
|
|
|
|
$where['route_code'] = $request->route_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('dep_icao')) {
|
|
|
|
$where['dpt_airport_id'] = $request->dep_icao;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->filled('arr_icao')) {
|
|
|
|
$where['arr_airport_id'] = $request->arr_icao;
|
2017-12-05 00:59:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->pushCriteria(new WhereCriteria($request, $where));
|
|
|
|
return $this;
|
|
|
|
}
|
2017-06-18 06:25:36 +08:00
|
|
|
}
|