A Laravel wrapper for thephpleague's Fractal package

Overview

laravel-api-response

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A Laravel wrapper for thephpleague's Fractal package

Install

Via Composer

composer require lykegenes/laravel-api-response

Then, add this to your Service Providers :

Lykegenes\ApiResponse\ServiceProvider::class,

...and this to your Aliases :

'ApiResponse' => Lykegenes\ApiResponse\Facades\ApiResponse::class,

Optionally, you can publish and edit the configuration file :

php artisan vendor:publish --provider="Lykegenes\ApiResponse\ServiceProvider" --tag=config

Usage

The easiest way to use this package is to call the make() function from the facade. It will try to guess your input. For the transformers, see the docs from the Fractal package here.

// You can use a class directly to return a paginated collection
return ApiResponse::make(User::class, UserTransformer::class);

// You can also use an Eloquent Query
return ApiResponse::make(User::where('age', '<', '40'), UserTransformer::class);

// This will return a single object
return ApiResponse::make(User::findOrFail($id), UserTransformer::class);

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP

MailChimp API Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP. I hate complex wrappers. This lets you get from the MailChimp API do

Google Translator Api Wrapper For Php Developers.

Google Translator Api Wrapper For Php Developers.

An unofficial wrapper client for lknpd.nalog.ru API

Unofficial MoyNalog API client An unofficial wrapper client for lknpd.nalog.ru API Install Via Composer $ composer require shoman4eg/moy-nalog Usage S

A Gitlab API wrapper that helps to automate common actions on CI jobs

Gitlab CI client This is a Gitlab API wrapper that helps to automate common actions on CI jobs (eg: Open a merge request, Open or close an issue etc)

OVHcloud APIs lightweight PHP wrapper

Lightweight PHP wrapper for OVHcloud APIs - The easiest way to use OVHcloud APIs in your PHP applications - Compatible with PHP 7.4, 8.0, 8.1 - Not affiliated with OVHcloud

The Official Vultr API PHP Wrapper

WIP - This is not the final API Client. Unstable release use with caution. Vultr API PHP Client. Getting Started Must have a PSR7, PSR17, and PSR18 Co

PSR-18 compliant Circuit Breaker wrapper

Interrupt PSR-18 compliant Circuit Breaker wrapper. Acknowledgement This library is heavily inspired by: ackintosh/ganesha PrestaShop/circuit-breaker

A Laravel package to retrieve pageviews and other data from Google Analytics
A Laravel package to retrieve pageviews and other data from Google Analytics

Retrieve data from Google Analytics Using this package you can easily retrieve data from Google Analytics. Here are a few examples of the provided met

A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

Comments
  • Merge for release v1.2.0

    Merge for release v1.2.0

    • Fixed bug with collections
    • Removed Searchable dependency
    • Allow Enabling/Disabling features in config
    • Allow setting default values for parameters in config
    • Support returning all the data on a single page when "per_page" = -1
    opened by patricksamson 0
Releases(1.2.0)
  • 1.2.0(Oct 27, 2015)

    • Allow Enabling/Disabling features in config
    • Allow setting default values for parameters in config
    • Support returning all the data on a single page when "per_page" = -1
    • Fixed bug with collections
    • Removed Searchable dependency
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Sep 29, 2015)

    I rewrote the whole thing in a much more modular fashion. Some changes :

    • Added tests
    • Switch to Nicolaslopezj\Searchable\SearchableTrait for the search function
    • Add support for Collection objects as input (except no search function for those)
    Source code(tar.gz)
    Source code(zip)
Owner
Patrick Samson
Patrick Samson
Laravel 8.x package wrapper library for Metatrader 5 Web API

Laravel 8.x package wrapper library for Metatrader 5 Web API

Ali A. Dhillon 10 Nov 13, 2022
laravel wrapper for dicom images services

laravel wrapper for dicom images services

Laravel Iran Community 4 Jan 18, 2022
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Laravel wrapper for the Facebook Graph PHP 8 SDK

Laravel Facebook Graph SDK Installation Getting started with Laravel Facebook Graph is easy - first, install the package via composer composer require

Joel Butcher 44 Dec 8, 2022
A PHP Stream wrapper for Amazon S3

S3StreamWrapper A simple stream wrapper for Amazon S3. Example <?php use S3StreamWrapper\S3StreamWrapper; S3StreamWrapper::register(); $options = a

Gijs Kunze 21 Nov 23, 2021
A PHP wrapper for Spotify's Web API.

Spotify Web API PHP This is a PHP wrapper for Spotify's Web API. It includes the following: Helper methods for all API endpoints: Information about ar

Jonathan Wilsson 796 Jan 8, 2023
Simple Curl based wrapper for Binance API for PHP scripts

Simple Curl based wrapper for Binance API for PHP scripts Feaures API support for SPOT data/trading FAPI/DAPI support for futures data/trading Curl-on

Mr Crypster 22 May 1, 2022
Google Drive Api Wrapper by PHP

GoogleDrive Api Wrapper usage at first you need to create oauth client on google cloud platform. so go to the your google console dashboard and create

Arash Abedi 2 Mar 24, 2022
An elegant wrapper around Google Vision API

STILL UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION Requires PHP 8.0+ For feedback, please contact me. This package provides an elegant wrapper around

Ahmad Mayahi 24 Nov 20, 2022
An asynchronous ClamAV wrapper written in PHP with amphp/socket

amphp-clamav An asynchronous ClamAV wrapper written with amphp/socket Installing composer require pato05/amphp-clamav Examples Ping and scan of a fil

Pato05 4 Feb 28, 2022