hesto/fractalfy
Fractalfy
Laravel Wrapper for Fractal
Usage
Step 1: Install Through Composer
composer require hesto/fractalfy
Step 2: Register Service Provider
Add your new provider to the providers array of config/app.php:
'providers' => [
// ...
Hesto\Fractalfy\FractalfyServiceProvider::class,
// ...
],
Fractal methods
Extend your controller with FractalfyController
class DashboardController extends FractalfyController
{
...
}
Return collection
$users = Users::all();
return $this->fractal
->collection($users, new UserTransformer)
->get();
Return resource with pagination
$users = Users::all();
return $this->fractal
->paginate($users, new UserTransformer)
->get();
Fractalfy Helpers
Use Fractalfy Helpers (already included in FractalfyController)
Popular
return $this->respondOK();
return $this->respondNotFound();
return $this->respondUnauthorized();
return $this->respondUnprocessable();
return $this->respondBadRequest();
return $this->respondWithSuccess(200); //any success code
return $this->respondWithError(400); //any success code
Other
return $this->respondOK($message); //pass message to respond
return $this->setMessage($message)->respondOK();
return $this->setMessage($message)->setStatusCode($statuscode)->respondWithSuccess();
return $this->setMessage($message)->setStatusCode($statuscode)->respondWithError();
Related Packages
eventhomes/laravel-apicontroller
Simplified API controller, inspired by Jeffrey Way. Compatible with Laravel 5+ a...
94,247
8
cyvelnet/laravel5-fractal
A simple fractal service provider and transformer generator with model attribute...
189,327
79
flugger/laravel-responder
A Laravel Fractal package for building API responses, giving you the power of Fr...
1,600,377
889