-
Notifications
You must be signed in to change notification settings - Fork 66
Other Examples
Selahattin Ünlü edited this page Jan 4, 2017
·
7 revisions
/api/users?columns=name,age,city_id
-
The resulting query =
Users::select(['name', 'age', 'city_id'])
For relations
/api/users?columns=*,city.id,city.name&includes=city
- The resulting query =
User::with(['city' => function($q) {
return $q->select(['id', 'name']);
}])->select(['*'])
/api/users?includes=city,country,town
-
The resulting query =
Users::with(['city', 'country', 'town'])
/api/users?limit=3
-
The resulting query =
Users::take(3)
For unlimited
/api/users?limit=unlimited
/api/users?order_by=name,asc
-
The resulting query =
Users::orderBy('name', 'asc')
You can sort by random:
-
/api/users?order_by=random
, -
The resulting query=
Users::orderBy(DB::raw('RAND()'))
You can sort by multiple columns:
/api/users?order_by=name,asc|age,desc|...
-
The resulting query =
Users::orderBy('name', 'asc')->orderBy('age', 'desc')
/api/users?page=2
-
The resulting query =
Users::skip(2 - 1 * {limit})
/api/users?appends=is_admin,balance
- This will add "is_admin and balance" to Model's $appends property.
Then you can access "is_admin" and "balance" in the response.
https://laravel.com/docs/5.3/eloquent-serialization#appending-values-to-json
/api/users?name=Selahattin
-
The resulting query =
Users::where('name', '=', 'Selahattin')
/api/users?name!=Selahattin
-
The resulting query =
Users::where('name', '!=', 'Selahattin')
/api/users?name=*se
-
The resulting query =
Users::where('name', 'like', '%se')
/api/users?name=se*
-
The resulting query =
Users::where('name', 'like', 'se%')
/api/users?name=\*se\*
-
The resulting query =
Users::where('name', 'like', '%se%')
/api/users?age<18
-
The resulting query =
Users::where('age', '<', 18)
/api/users?age>18
-
The resulting query =
Users::where('age', '>', 18)
/api/users?age<=18
-
The resulting query =
Users::where('age', '<=', 18)
/api/users?age>=18
-
The resulting query =
Users::where('age', '>=', 18)
/api/users?age[]=18&age[]=23
-
The resulting query =
Users::whereIn('age', [18, 23])
/api/users?age[]!=18&age[]!=23
-
The resulting query =
Users::whereNotIn('age', [18, 23])
/api/users?updated_at=[null]
-
The resulting query =
Users::whereNull('updated_at')
/api/users?updated_at!=[null]
-
The resulting query =
Users::whereNotNull('updated_at')
For whereBetween:
/api/users?age>10&age<20
-
The resulting query
Users::where('age', '>', 10)->where('age', '<', 20)