PHP code example of codingphase / fractalfy
1. Go to this page and download the library: Download codingphase/fractalfy library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codingphase / fractalfy example snippets
'providers' => [
// ...
CodingPhase\Fractalfy\FractalfyServiceProvider::class,
// ...
],
class DashboardController extends FractalfyController
{
...
}
$users = Users::all();
return $this->fractal
->collection($users, new UserTransformer)
->get();
$users = Users::all();
return $this->fractal
->paginate($users, new UserTransformer)
->get();
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
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();