zeng407 / l5-repository
Laravel 5 - Repositories to the database layer
v2.8
2018-09-03 06:21 UTC
Requires
- illuminate/config: ~5.0
- illuminate/console: ~5.0
- illuminate/database: ~5.0
- illuminate/filesystem: ~5.0
- illuminate/http: ~5.0
- illuminate/pagination: ~5.0
- illuminate/support: ~5.0
- prettus/laravel-validation: 1.1.*
Suggests
- league/fractal: Required to use the Fractal Presenter (0.12.*).
- prettus/laravel-validation: Required to provide easy validation with the repository (1.1.*)
- robclancy/presenter: Required to use the Presenter Model (1.3.*)
- dev-master
- v2.8
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7
- 2.6.32
- 2.6.31
- 2.6.30
- 2.6.29
- 2.6.28
- 2.6.27
- 2.6.26
- 2.6.25
- 2.6.24
- 2.6.23
- 2.6.22
- 2.6.21
- 2.6.20
- 2.6.19
- 2.6.18
- 2.6.17
- 2.6.16
- 2.6.15
- 2.6.14
- 2.6.13
- 2.6.12
- 2.6.11
- 2.6.10
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- v1.0
- dev-develop
- dev-3.0-develop
This package is not auto-updated.
Last update: 2025-03-31 02:32:12 UTC
README
install
composer require zeng407/l5-repository
filtering
give serchable columns like this
class UserRepository extedns BaseRepository
{
protected $fieldSearchable = [
'user_name' => [
'column' => 'name'
// default column value is 'user_name' if you don't specify column name
],
'age' => [
'operators' => ['=','in','>=']
//limit operators input
],
'gender',
'post_title' => [
'relation' => 'posts', // give the relation name in User Model
'column' => 'title'
],
'phone_number' => [
'relation' => 'profile.phones'
]
];
}
then you can do these query
localhost/users?user_name_like="john"
// select * from users where name like '%john%'
localhost/users?age_gte=20
// select * from users where age >= 20
localhost/users?gender=female
// select * from users where gender = 'female'
localhost/users?age_in[]=20&age_in[]=30age_in[]=35
// select * from users where age in (20,30,35)
localhost/users?post_title_like='announcement'
// select * from users where exists
// (select * from posts where posts.user_id = users.id
//. and posts.title like '% announcement%')
the operations are defined at
class RequestCriteria implements CriteriaInterface {
protected $operatorMap = [
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<=',
'like' => 'like',
'in' => 'in'
];
}
sorting
class UserRepository extedns BaseRepository
{
protected $sortable = [
'user_name' => [
'column' => 'name'
],
'post_title' => [
'join' => 'posts',
'column' => 'title'
],
'phone_number' => [
'relation' => 'profiles.phones'
//give the table name, not the relation name in User model
]
];
}
query
localhost/users?order_by=user_name
// select * from users order by name
localhost/users?order_by=phone_number&order_dir=desc (default order_dir=asc)
// select * form users
// left join profiles on profiles.user_id = users.id
// join phones on phones.profile_id = profiles.id
// order by phone_number asec