Download the PHP package sukohi/flexible-resource without Composer

On this page you can find all versions of the php package sukohi/flexible-resource. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package flexible-resource

FlexibleResource

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

Installation

composer require sukohi/flexible-resource:2.*

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

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

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

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

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 is available.

License

This package is licensed under the MIT License.

Copyright 2018 Sukohi Kuhoh


All versions of flexible-resource with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^5.7|^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sukohi/flexible-resource contains the following files

Loading the files please wait ...