-
Notifications
You must be signed in to change notification settings - Fork 0
4. Request
You can safely select the model from the database with their corresponding field name, example
?name=DimasSatrioTo find the data with the exact name.
?name=$DimasTo find the data with name Like %Dimas% operator (non case sensitive )
?age=>5To find the data with age more than 5
?age=<5To find the data with age less than 5
?age=|a,bTo find the data between value a and b
?age=1,3,4,5To find the data with age 1, 3, 4, 5 (you could use id as parameter too!)
?age=!5To find all the data that is not aged 5
?age={a,b=}cTo find entity that have attributes age.a.b == c
?user^age=aTo find entity that have relation user with age == a
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.
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"
}
}
}You could also order the result with special request key orderBy
?limit=10&page=5&orderBy=>nameOrder By name Ascending
?limit=10&page=5&orderBy=>name,<idOrder By name Ascending, and then id Descending
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
}You could easily get all the entity that have been soft deleted via query parameter soft=true
?soft=trueBy 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;
}