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

42 lines
950 B
PHP
Raw Normal View History

2017-08-15 07:26:20 +08:00
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
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 {
$flights = $this->flightRepo->searchCriteria($request)->paginate();
} catch (RepositoryException $e) {
return response($e, 503);
}
return FlightResource::collection($flights);
2017-08-15 07:26:20 +08:00
}
}