hesto / fractalfy
Laravel wrapper for Fractal.
Installs: 1 605
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.9
- illuminate/support: ~5.1.0|~5.2.0|~5.3.0|~5.4.0
- league/fractal: ^0.14.0
Requires (Dev)
- illuminate/pagination: ^5.3
This package is not auto-updated.
Last update: 2024-12-07 20:49:55 UTC
README
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();