PHPackages                             sukohi/flexible-resource - 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. sukohi/flexible-resource

ActiveLibrary

sukohi/flexible-resource
========================

A Laravel package that allows you to flexibly generate resource.

2.0.0(5y ago)0186MITPHP

Since Dec 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/SUKOHI/FlexibleResource)[ Packagist](https://packagist.org/packages/sukohi/flexible-resource)[ RSS](/packages/sukohi-flexible-resource/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

FlexibleResource
================

[](#flexibleresource)

A Laravel package that allows you to flexibly generate resource.
This package is maintained under L6.x.

Installation
============

[](#installation)

```
composer require sukohi/flexible-resource:2.*

```

Preparation
===========

[](#preparation)

Set `FlexibleResourceTrait` like so.

```
use Sukohi\FlexibleResource\Traits\FlexibleResourceTrait;

class ResourceController extends Controller
{
    use FlexibleResourceTrait;

```

Also Routing for the controller.

```
Route::get('resource', 'ResourceController@get');

```

Usage
=====

[](#usage)

Basic usage
-----------

[](#basic-usage)

Add private method(s) to your controller.

```
class ResourceController extends Controller
{
    use FlexibleResourceTrait;

    private function userTypes() {

        return [
           1 => 'admin',
           2 => 'owner',
           3 => 'user'
       ];

    }

```

In this case, you can get `userTypes` through the following URL.

```
https://example.com/resource?keys=userTypes

```

Example:

```
{
    "userTypes":{
        "1":"admin",
        "2":"owner",
        "3":"user"
    }
}

```

Multiple methods
----------------

[](#multiple-methods)

Of course, you also can set multiple methods like this.

```
class ResourceController extends Controller
{
    use FlexibleResourceTrait;

    private function userTypes() {

        // ...

    }

    private function userNames() {

        // ...

    }

```

In this case, you need to join some keys with `|`.

```
https://example.com/resource?keys=userTypes|userNames

```

with Arguments
--------------

[](#with-arguments)

This package supports arguments for each method. If you'd like to call a method which need to 3 arguments, set parameters.

```
private function yourMethod($value_1, $value_2, $value_3) {

    // ...

}

```

For your information, you can set default value.

```
private function yourMethod($value_1 = null, $value_2 = 10, $value_3 = 1000) {

    // ...

}

```

URL:

```
https://example.com/resource?keys=userTypes:value1,value2,value3

```

Conversion to collection
========================

[](#conversion-to-collection)

If your controller already has a method called `userTypes`, `userTypeCollection` is also automatically available.

In this case resource data will be converted to collection like so.

```
{
    "userTypeCollection":[
        {"key":1, "value":"admin"},
        {"key":2, "value":"owner"},
        {"key":3, "value":"user"}
    ]
}

```

In addition, you can change keys through `$auto_collections`.

```
class ResourceController extends Controller
{
    protected $auto_collections = [
        'userTypes' => ['id' => 'type']
    ];

```

As a result, resource data is like so.

```
{
    "userTypeCollection":[
        {"id":1, "type":"admin"},
        {"id":2, "type":"owner"},
        {"id":3, "type":"user"}
    ]
}

```

Or `*` is also available as default.

```
class ResourceController extends Controller
{
    protected $auto_collections = [
        '*' => ['value' => 'text']
    ];

```

with Vue.js

If you'd like to get your resource data in Vue.js, a dedicated package called [v-flexible-resource](https://github.com/SUKOHI/v-flexible-resource) is available.

License
=======

[](#license)

This package is licensed under the MIT License.

Copyright 2018 Sukohi Kuhoh

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~128 days

Total

5

Last Release

2188d ago

Major Versions

1.0.x-dev → 2.0.02020-05-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/2980d59b309d45df3f2e6e51b1d336614da063240b8f76f873f287cd745ec5db?d=identicon)[Sukohi](/maintainers/Sukohi)

---

Top Contributors

[![SUKOHI](https://avatars.githubusercontent.com/u/5362394?v=4)](https://github.com/SUKOHI "SUKOHI (6 commits)")

### Embed Badge

![Health badge](/badges/sukohi-flexible-resource/health.svg)

```
[![Health](https://phpackages.com/badges/sukohi-flexible-resource/health.svg)](https://phpackages.com/packages/sukohi-flexible-resource)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)

PHPackages © 2026

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