Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit ad96d44

Browse files
committed
Merge branch 'release/4.1.0'
2 parents badb1a5 + cec6836 commit ad96d44

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog
2+
## v.4.1.0
3+
- compatibility with PHP version 8.x (updated composer.json file)
4+
- DateCriteria now accept "column" parameter
5+
- add new criteria
6+
* FindWhereOrWhereCriteria
7+
* FindWhereNotIn
28
## v.4.0.1
39
- update ext-json version to "*" in composer.json file
410
## v.4.0.0

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ List of criteria, provider by default with this package:
141141
* DateCriteria - search records with given date range (by created_at field)
142142
* FindWhereCriteria
143143
* FindWhereInCriteria
144+
* FindWhereNotInCriteria
144145
* LimitCriteria
145146
* OrWhereCriteria
146147
* Select2Criteria - criteria useful when implementing Select2
147148
* OffsetCriteria
149+
* FindWhereOrWhereCriteria
148150

149151
#### Caching
150152
___
@@ -166,6 +168,8 @@ of choice. Trait will handle cache for methods:
166168
* paginate()
167169
* simplePaginate()
168170

171+
You can user criteria with this functions, and results will be cached.
172+
169173
Repository automatically flush cache, when method create(), updateOrCreate(), update(),
170174
delete() is call.
171175

@@ -211,7 +215,7 @@ $this-exampleService->getRepository->skipCache()->findWhere(...)
211215
```
212216

213217
##### Disable cache
214-
To quick disable cache i.ex for debugging, set REPOSITORY_CACHE variable for false in .env
218+
To quick disable cache i.ex for debugging, set REPOSITORY_CACHE variable to false in .env
215219
```dotenv
216220
REPOSITORY_CACHE=false
217221
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"laravel"
1111
],
1212
"require": {
13-
"php": "^7.3",
13+
"php": "^7.3|^8.0",
1414
"ext-json": "*",
1515
"ext-libxml": "*",
1616
"ext-simplexml": "*",

src/Repositories/Criteria/DateCriteria.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,28 @@ class DateCriteria extends CoreRepositoryCriteria
2828
*/
2929
private $dateTo;
3030

31+
/**
32+
* Column name to search.
33+
*
34+
* @var string
35+
*/
36+
private $column;
37+
3138
/**
3239
* DateCriteria constructor.
3340
*
3441
* @param null|string $dateFrom
3542
* @param null|string $dateTo
43+
* @param string $column
3644
*/
3745
public function __construct(
3846
?string $dateFrom,
39-
?string $dateTo
47+
?string $dateTo,
48+
string $column = Model::CREATED_AT
4049
) {
4150
$this->dateFrom = $dateFrom;
4251
$this->dateTo = $dateTo;
52+
$this->column = $column;
4353
}
4454

4555
/**
@@ -56,11 +66,11 @@ public function __construct(
5666
public function apply($entity)
5767
{
5868
if ($this->dateFrom !== null) {
59-
$entity = $entity->where(Model::CREATED_AT, '>=', $this->dateFrom);
69+
$entity = $entity->where($this->column, '>=', $this->dateFrom);
6070
}
6171

6272
if ($this->dateTo !== null) {
63-
$entity = $entity->where(Model::CREATED_AT, '<=', $this->dateTo);
73+
$entity = $entity->where($this->column, '<=', $this->dateTo);
6474
}
6575

6676
return $entity;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace PacerIT\LaravelRepository\Repositories\Criteria;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
/**
9+
* Class FindWhereNotInCriteria.
10+
*
11+
* @author Wiktor Pacer <[email protected]>
12+
*
13+
* @since 09/12/2020
14+
*/
15+
class FindWhereNotInCriteria extends CoreRepositoryCriteria
16+
{
17+
/**
18+
* @var string
19+
*/
20+
protected $column;
21+
22+
/**
23+
* @var array
24+
*/
25+
protected $notIn;
26+
27+
/**
28+
* FindWhereNotInCriteria constructor.
29+
*
30+
* @param string $column
31+
* @param array $notIn
32+
*/
33+
public function __construct(string $column, array $notIn)
34+
{
35+
$this->column = $column;
36+
$this->notIn = $notIn;
37+
}
38+
39+
/**
40+
* Apply criteria on entity.
41+
*
42+
* @param Model|Builder $entity
43+
*
44+
* @return Model|Builder
45+
*
46+
* @author Wiktor Pacer <[email protected]>
47+
*
48+
* @since 2019-07-05
49+
*/
50+
public function apply($entity)
51+
{
52+
return $entity->whereNotIn($this->column, $this->notIn);
53+
}
54+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace PacerIT\LaravelRepository\Repositories\Criteria;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
/**
9+
* Class FindWhereOrWhereCriteria.
10+
*
11+
* @author Wiktor Pacer <[email protected]>
12+
*
13+
* @since 09/12/2020
14+
*/
15+
class FindWhereOrWhereCriteria extends CoreRepositoryCriteria
16+
{
17+
/**
18+
* @var array
19+
*/
20+
protected $where;
21+
22+
/**
23+
* @var array
24+
*/
25+
protected $orWhere;
26+
27+
/**
28+
* FindWhereCriteria constructor.
29+
*
30+
* @param array $where
31+
* @param array $orWhere
32+
*/
33+
public function __construct(array $where, array $orWhere = [])
34+
{
35+
$this->where = $where;
36+
$this->orWhere = $orWhere;
37+
}
38+
39+
/**
40+
* Apply criteria on entity.
41+
*
42+
* @param Model|Builder $entity
43+
*
44+
* @return Model|Builder
45+
*
46+
* @author Wiktor Pacer <[email protected]>
47+
*
48+
* @since 2019-07-05
49+
*/
50+
public function apply($entity)
51+
{
52+
return $entity->where(function ($query) {
53+
$query->where($this->where);
54+
55+
foreach ($this->orWhere as $where) {
56+
$query->orWhere($where);
57+
}
58+
});
59+
}
60+
}

0 commit comments

Comments
 (0)