2017 © Pedro Peláez
 

library laravel-where-plus

Extra where scopes for Laravel Eloquent

image

blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  • Tuesday, February 13, 2018
  • by mhkb
  • Repository
  • 5 Watchers
  • 1 Stars
  • 2,351 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 63 % Grown

The README.md

laravel-where-plus

Extra where scopes for Laravel Models, (*1)

Functions: * whereOrEmptyOrNull($column, $value, $ignore) * whereInColumn($column, $value) * whereNotInColumn($column, $value) * whereIfNull($column, $ifNull, $operator = null, $value = null, $boolean = 'and'), (*2)

whereOrEmptyOrNull

This adds a where condition for when a $column should be equal to $value, but not equal to a $ignore, (*3)

  $query->whereOrEmptyOrNull('Country', $input['country'], '');

If $input['country'] is not equal to '' then this will be the equivalent of:, (*4)

  $query->where('Country', $input['country']);

Otherwise if $input['country'] === '' then a where statement isn't added., (*5)

Likewise, a default value could be added, eg., (*6)

$query->whereOrEmptyOrNull('Country', $input['country'], 'Australia');

If you wanted to only add a where statement when $input['country'] isn't 'Australia'., (*7)

This can also be run with an array of columns, e.g.:, (*8)

  $query->whereOrEmptyOrNull([
          'Country' => $input['country'],
          'State' => $input['state'],
          'Locality' => $input['locality']
      ], '', '');

which would add where statements for Country, State and Locality if the input fields weren't empty., (*9)

whereInColumn

This adds a where condition to only include records where $value is in $column. The value of $column should be a comma delimited list., (*10)

For example:, (*11)

  $query->whereInColumn('Country', 'Australia');

In SQL, this would be the equivalent of:, (*12)

  WHERE CONCAT(',', `Country`, ',') LIKE '%,Australia,%'

whereNotInColumn

This adds a where condition to only include records where $value is not in $column. The value of $column should be a comma delimited list., (*13)

For example:, (*14)

  $query->whereNotInColumn('Country', 'Australia');

In SQL, this would be the equivalent of:, (*15)

  WHERE CONCAT(',', `Country`, ',') NOT LIKE '%,Australia,%'

whereIfNull($column, $ifNull, $operator = null, $value = null, $boolean = 'and')

This adds a where condition with the column wrapped in an SQL 'IFNULL' with the column as the first parameter and $ifNull as the second parameter., (*16)

For example:, (*17)

  $query->whereIfNull('Country', 'Australia', '=', 'New Zealand');

In SQL, this would be the equivalent of:, (*18)

  WHERE IFNULL(`Country`, 'Australia') = 'New Zealand'

Aggregates

Available scopes

  • addCount
  • addSum
  • addAvg
  • addMin
  • addMax

Example

Calls::make()
  ->select(['calltype'])
  ->addCount('id')
  ->addSum('seconds')
  ->addSum('seconds', 'seconds2')
  ->groupBy('calltype');

In SQL, this would be the equivalent of:, (*19)

  select calltype, count(id), sum(seconds), sum(charge) 
    from calls 
   group by calltype

Group and Order

Available scopes

  • groupByIndex
  • orderByIndex

Example

Calls::make()
  ->select(['calltype', 'description'])
  ->addSum('charge')
  ->groupByIndex(1, 2);
  ->orderByIndex(1);
  select calltype, description, sum(charge) 
    from calls 
   group by 1, 2
   order by 1

The Versions

13/02 2018

dev-master

9999999-dev https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

13/02 2018

dev-analysis-qM5GM2

dev-analysis-qM5GM2 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

13/02 2018

0.1.7

0.1.7.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

12/02 2018

dev-analysis-qrMjRg

dev-analysis-qrMjRg https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

12/02 2018

0.1.6

0.1.6.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

21/01 2018

0.1.5

0.1.5.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

18/01 2018

0.1.4

0.1.4.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

18/01 2018

0.1.3

0.1.3.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

18/01 2018

0.1.2

0.1.2.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

17/01 2018

0.1.1

0.1.1.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where

16/01 2018

0.1.0

0.1.0.0 https://github.com/blasttech/laravel-where-plus

Extra where scopes for Laravel Eloquent

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Blair

laravel eloquent model where