Convert flight transformer to the native Laravel resource object
This commit is contained in:
@@ -7,27 +7,33 @@ 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;
|
||||
|
||||
|
||||
class FlightController extends AppBaseController
|
||||
{
|
||||
protected $flightRepo;
|
||||
|
||||
public function __construct(
|
||||
FlightRepository $flightRepo
|
||||
) {
|
||||
public function __construct(FlightRepository $flightRepo) {
|
||||
$this->flightRepo = $flightRepo;
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$flight = $this->flightRepo->find($id);
|
||||
return fractal($flight, new FlightTransformer())->respond();
|
||||
FlightResource::withoutWrapping();
|
||||
return new FlightResource($flight);
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
||||
return fractal($flights, new FlightTransformer())->respond();
|
||||
try {
|
||||
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
||||
} catch (RepositoryException $e) {
|
||||
return response($e, 503);
|
||||
}
|
||||
return FlightResource::collection($flights);
|
||||
//return fractal($flights, new FlightTransformer())->respond();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user