Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
3b32762f
Unverified
Commit
3b32762f
authored
Oct 31, 2018
by
Nicolas Widart
Committed by
GitHub
Oct 31, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #639 from xfudox/master
added where() and with() to EloquentBaseRepository
parents
24d1aeb2
caaafd92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
BaseRepository.php
Modules/Core/Repositories/BaseRepository.php
+16
-0
BaseCacheDecorator.php
Modules/Core/Repositories/Cache/BaseCacheDecorator.php
+20
-0
EloquentBaseRepository.php
...les/Core/Repositories/Eloquent/EloquentBaseRepository.php
+22
-0
No files found.
Modules/Core/Repositories/BaseRepository.php
View file @
3b32762f
...
...
@@ -98,4 +98,20 @@ interface BaseRepository
* @return bool
*/
public
function
clearCache
();
/**
* Add where statement to current builder
*
* @param string $field
* @param string|int $value
* @param string $operator
*/
public
function
where
(
string
$field
,
$value
,
string
$operator
=
null
);
/**
* Eager relationship(s) loading
*
* @param array|string $relationships
*/
public
function
with
(
$relationships
);
}
Modules/Core/Repositories/Cache/BaseCacheDecorator.php
View file @
3b32762f
...
...
@@ -220,4 +220,24 @@ abstract class BaseCacheDecorator implements BaseRepository
$this
->
entityName
);
}
/**
* @inheritdoc
*/
public
function
where
(
string
$field
,
$value
,
string
$operator
=
null
)
{
return
$this
->
remember
(
function
()
use
(
$field
,
$value
,
$operator
)
{
return
$this
->
repository
->
where
(
$field
,
$value
,
$operator
);
});
}
/**
* @inheritdoc
*/
public
function
with
(
$relationships
)
{
return
$this
->
remember
(
function
()
use
(
$relationships
)
{
return
$this
->
repository
->
with
(
$relationships
);
});
}
}
Modules/Core/Repositories/Eloquent/EloquentBaseRepository.php
View file @
3b32762f
...
...
@@ -191,4 +191,26 @@ abstract class EloquentBaseRepository implements BaseRepository
{
return
true
;
}
/**
* @inheritdoc
*/
public
function
where
(
string
$field
,
$value
,
string
$operator
=
null
)
{
if
(
$operator
===
null
)
{
$operator
=
'='
;
}
else
{
list
(
$value
,
$operator
)
=
[
$operator
,
$value
];
}
return
$this
->
model
->
where
(
$field
,
$operator
,
$value
);
}
/**
* @inheritdoc
*/
public
function
with
(
$relationships
)
{
return
$this
->
model
->
with
(
$relationships
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment