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

40 lines
1.0 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 App\Http\Controllers\AppBaseController;
use App\Models\Transformers\FlightTransformer;
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 AppBaseController
{
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
}
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);
//return fractal($flights, new FlightTransformer())->respond();
2017-08-15 07:26:20 +08:00
}
}