2015-11-03 20:03:24 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Utils;
|
|
|
|
use Response;
|
|
|
|
use League\Fractal;
|
|
|
|
use League\Fractal\Manager;
|
|
|
|
use App\Ninja\Serializers\ArraySerializer;
|
|
|
|
|
|
|
|
class BaseAPIController extends Controller
|
|
|
|
{
|
|
|
|
protected $manager;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->manager = new Manager();
|
|
|
|
$this->manager->setSerializer(new ArraySerializer());
|
|
|
|
}
|
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
protected function returnData($resource, $class = false)
|
2015-11-03 20:03:24 +01:00
|
|
|
{
|
|
|
|
$response = $this->manager->createData($resource)->toArray();
|
2015-11-05 09:44:48 +01:00
|
|
|
|
|
|
|
if ($class) {
|
|
|
|
$response = [$class => $response];
|
|
|
|
}
|
|
|
|
|
2015-11-03 20:03:24 +01:00
|
|
|
$response = json_encode($response, JSON_PRETTY_PRINT);
|
|
|
|
$headers = Utils::getApiHeaders();
|
|
|
|
|
|
|
|
return Response::make($response, 200, $headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|