Package Data | |
---|---|
Maintainer Username: | lostincode |
Maintainer Contact: | roundedvision@gmail.com (Bill Richards) |
Package Create Date: | 2015-06-21 |
Package Last Update: | 2020-01-28 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-26 15:01:06 |
Package Statistics | |
---|---|
Total Downloads: | 88,716 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 7 |
Total Watchers: | 5 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A simple api controller helper utilizing league fractal. You also get all the functionality provided by https://github.com/eventhomes/laravel-apicontroller
composer require eventhomes/laravel-fractalhelper
By default, this helper will use ArraySerializer(), no setup required. You may, however, need to parse the GET includes.
...
use EventHomes\Api\FractalHelper;
class MyController extends Controller {
use FractalHelper;
public function __construct(Request $request)
{
$this->parseIncludes($request->get('includes', ''));
}
}
If you need to change the default ArraySerializer(), you can modify.
...
use EventHomes\Api\FractalHelper;
class MyController extends Controller {
use FractalHelper;
public function __construct(Manager $manager, Request $request)
{
$manager->setSerializer(new JsonApiSerializer);
$this->setFractal($manager)->parseIncludes($request->get('includes', ''));
}
}
public function show($id)
{
$user = User::find($id);
return $this->respondWithItem($user, new UserTransformer);
}
public function index()
{
$users = User::all();
return $this->respondWithCollection($users, new UserTransformer);
}
public function index()
{
$users = User::paginate(10);
return $this->respondWithCollection($users, new UserTransformer);
}