phpvms/app/Http/Controllers/Api/FlightController.php

45 lines
1.1 KiB
PHP
Raw Normal View History

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