2017 © Pedro Peláez
 

library l5-repository

Laravel 5 - Repositories to the database layer

image

zeng407/l5-repository

Laravel 5 - Repositories to the database layer

  • Monday, July 30, 2018
  • by zeng407
  • Repository
  • 0 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 546 Forks
  • 0 Open issues
  • 75 Versions
  • 0 % Grown

The README.md

Simple RequestCriteria

install

composer require zeng407/l5-repository

filtering

give serchable columns like this, (*1)

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, (*2)

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, (*3)

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, (*4)

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

The Versions

13/03 2015

1.0.4

1.0.4.0

Laravel 5 - Repositories to abstract the database layer

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository eloquent model

06/03 2015

1.0.3

1.0.3.0

Laravel 5 - Repositories to abstract the database layer

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository eloquent model

12/02 2015

1.0.2

1.0.2.0

Laravel 5 - Repositories to abstract the database layer

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

laravel repository eloquent model

12/02 2015

1.0.1

1.0.1.0

Laravel 5 - Repositories to abstract the database layer

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

laravel repository eloquent model

12/02 2015

1.0.0

1.0.0.0

Laravel 5 - Repositories to abstract the database layer

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

laravel repository eloquent model