Skip to content

4. Request

Dimas Satrio edited this page Feb 19, 2018 · 4 revisions

Get Collection Request

Selection with field name

You can safely select the model from the database with their corresponding field name, example

Equal Search
?name=DimasSatrio

To find the data with the exact name.

Like Search
?name=$Dimas

To find the data with name Like %Dimas% operator (non case sensitive )

More Than Search
?age=>5

To find the data with age more than 5

Less Than Search
?age=<5

To find the data with age less than 5

Between Search
?age=|a,b

To find the data between value a and b

In Search
?age=1,3,4,5

To find the data with age 1, 3, 4, 5 (you could use id as parameter too!)

Not Equal Search
?age=!5

To find all the data that is not aged 5

JSON Search
?age={a,b=}c

To find entity that have attributes age.a.b == c

Relation Search
?user^age=a

To find entity that have relation user with age == a

Scoping

You can also add scoping with parameter scope, it will work as long as the Model that you work with have implement the scope suggested.

Paginate with limit and page

To paginate your returned data, you could use special request key limit and page, don't forget you couldn't use limit and page as your field name (Might change in the future)

?limit=10&page=5
"meta": {
    "pagination": {
        "total": 119,
        "count": 10,
        "per_page": 10,
        "current_page": 5,
        "total_pages": 12,
        "links": {
            "previous": "http://ramencore.dev/users?page=4",
            "next": "http://ramencore.dev/users?page=6"
        }
    }
}

Order result with orderBy

You could also order the result with special request key orderBy

?limit=10&page=5&orderBy=>name

Order By name Ascending

?limit=10&page=5&orderBy=>name,<id

Order By name Ascending, and then id Descending

Invoke Relation with relation

RamenRest allow you to add relation of your model via request relation. This relation need to be setup first on your transformer files that extend from League\Fractal\TransformerAbstract. And then your model need to reference this transformer via getTransformer method.

public function getTransformer(){
    return $this->transformer; // Which need to be instantiated from League\Fractal\TransformerAbstract
}

Involve Soft Deleted entity with soft

You could easily get all the entity that have been soft deleted via query parameter soft=true

?soft=true

Post Item Request

Upload file easily

By adding $files array inside the model, and then reference it with getFiles() function. You could trigger, the upload files mechanism on the listed parameter. Be advised that this option is able to upload multiple files by referencing it as attributes[] parameter on the request body.

protected $files = [
    "avatar"
]

public function getFiles()
{
    return $this->files;
}