PHPackages                             shadowm2/coke - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. shadowm2/coke

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shadowm2/coke
=============

A layer between data source and output

0.02(7y ago)336PHPPHP &gt;=5.3.0

Since Aug 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/shadowm2/coke)[ Packagist](https://packagist.org/packages/shadowm2/coke)[ RSS](/packages/shadowm2-coke/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (5)Used By (0)

Beautiful API with Coke !
=========================

[](#beautiful-api-with-coke-)

Installation (Lumen)
--------------------

[](#installation-lumen)

```
$ composer require shadowm2/coke

```

Add this line in your bootstrap/app.php

```
$app->register(Shadow\Coke\CokeServiceProvider::class);

```

Use this alias for more comfort. add this line to your bootstrap/app.php

```
class_alias(\Shadow\Coke\Facades\Coke::class, 'Coke');

```

Usage
-----

[](#usage)

Define a function called "transform" in a model.

```
class User .... {
	...
	function transform()
	{
		return [
			'name'	=> $this->name,
			'token'	=> "dummy"
		];
	}
}

```

Then you can use Coke like this:

```
use Coke;

$user = User::first();
$response = Coke::transform($user);
return $response;

// Output : {"name": "sth", "token": "dummy"}

```

Input to coke must be in this form:

```
Coke::tranform($data): $data must be Collection|Model|LengthAwarePaginator

```

If you want to use another transform function on a model and have multiple transform functions for a model, pass another parameter as below:

```
$changes = [
	'App\User' => 'anotherFunction' // keys in this array are path to your models
];

Coke::transform($user, $changes);

```

Adding relationships is just a breeze. You should add your relationships in your queries and define transform functions in each used model.

```
$data = User::first()->posts()->where('post_type', 2)->get();
$response = Coke::transform($data);

/*
* Output: {'name': 'sth', 'token': 'dummy', 'posts': [{
*		...
*	}]}
*
*/

```

In this example, posts is a hasMany relationship so each post is transformed individually.

Pagination is also supported.

```
$users = User::paginate();
return Coke::Transform($users);

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2838d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/604eabe1d93f955b4423364401a3e7465cfcebc04542016229eef9031da08b9c?d=identicon)[shadowm2](/maintainers/shadowm2)

---

Top Contributors

[![shadowm2](https://avatars.githubusercontent.com/u/15728870?v=4)](https://github.com/shadowm2 "shadowm2 (14 commits)")

### Embed Badge

![Health badge](/badges/shadowm2-coke/health.svg)

```
[![Health](https://phpackages.com/badges/shadowm2-coke/health.svg)](https://phpackages.com/packages/shadowm2-coke)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
