2017-08-15 07:26:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
use Log;
|
2017-08-15 07:26:20 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
use App\Http\Controllers\AppBaseController;
|
2017-12-05 00:59:25 +08:00
|
|
|
use App\Repositories\FlightRepository;
|
2017-12-12 21:25:11 +08:00
|
|
|
use App\Http\Resources\Flight as FlightResource;
|
|
|
|
use Prettus\Repository\Exceptions\RepositoryException;
|
2017-08-15 07:26:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class FlightController extends AppBaseController
|
|
|
|
{
|
2017-12-05 00:59:25 +08:00
|
|
|
protected $flightRepo;
|
|
|
|
|
2017-12-12 21:25:11 +08:00
|
|
|
public function __construct(FlightRepository $flightRepo) {
|
2017-12-05 00:59:25 +08:00
|
|
|
$this->flightRepo = $flightRepo;
|
|
|
|
}
|
2017-08-15 12:36:49 +08:00
|
|
|
|
|
|
|
public function get($id)
|
|
|
|
{
|
2017-12-05 00:59:25 +08:00
|
|
|
$flight = $this->flightRepo->find($id);
|
2017-12-12 21:25:11 +08:00
|
|
|
FlightResource::withoutWrapping();
|
|
|
|
return new FlightResource($flight);
|
2017-08-15 12:36:49 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2017-08-15 07:26:20 +08:00
|
|
|
public function search(Request $request)
|
|
|
|
{
|
2017-12-12 21:25:11 +08:00
|
|
|
try {
|
|
|
|
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
|
|
|
} catch (RepositoryException $e) {
|
|
|
|
return response($e, 503);
|
|
|
|
}
|
2017-12-13 01:49:35 +08:00
|
|
|
|
2017-12-12 21:25:11 +08:00
|
|
|
return FlightResource::collection($flights);
|
2017-08-15 07:26:20 +08:00
|
|
|
}
|
|
|
|
}
|