Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Yeray Santana Hualde
syncEnrollments
Commits
9057c60a
Commit
9057c60a
authored
Apr 27, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #584 from bencorlett/develop
Adding having() support to the Fluent query builder.
parents
26730cd5
af6d76f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
query.php
laravel/database/query.php
+23
-0
grammar.php
laravel/database/query/grammars/grammar.php
+19
-1
No files found.
laravel/database/query.php
View file @
9057c60a
...
@@ -70,6 +70,13 @@ class Query {
...
@@ -70,6 +70,13 @@ class Query {
*/
*/
public
$groupings
;
public
$groupings
;
/**
* The HAVING clauses.
*
* @var array
*/
public
$havings
;
/**
/**
* The ORDER BY clauses.
* The ORDER BY clauses.
*
*
...
@@ -475,6 +482,22 @@ class Query {
...
@@ -475,6 +482,22 @@ class Query {
return
$this
;
return
$this
;
}
}
/**
* Add a having to the query.
*
* @param string $column
* @param string $operator
* @param mixed $value
*/
public
function
having
(
$column
,
$operator
,
$value
)
{
$this
->
havings
[]
=
compact
(
'column'
,
'operator'
,
'value'
);
$this
->
bindings
[]
=
$value
;
return
$this
;
}
/**
/**
* Add an ordering to the query.
* Add an ordering to the query.
*
*
...
...
laravel/database/query/grammars/grammar.php
View file @
9057c60a
...
@@ -19,7 +19,7 @@ class Grammar extends \Laravel\Database\Grammar {
...
@@ -19,7 +19,7 @@ class Grammar extends \Laravel\Database\Grammar {
*/
*/
protected
$components
=
array
(
protected
$components
=
array
(
'aggregate'
,
'selects'
,
'from'
,
'joins'
,
'wheres'
,
'aggregate'
,
'selects'
,
'from'
,
'joins'
,
'wheres'
,
'groupings'
,
'orderings'
,
'limit'
,
'offset'
,
'groupings'
,
'
havings'
,
'
orderings'
,
'limit'
,
'offset'
,
);
);
/**
/**
...
@@ -286,6 +286,24 @@ class Grammar extends \Laravel\Database\Grammar {
...
@@ -286,6 +286,24 @@ class Grammar extends \Laravel\Database\Grammar {
return
'GROUP BY '
.
$this
->
columnize
(
$query
->
groupings
);
return
'GROUP BY '
.
$this
->
columnize
(
$query
->
groupings
);
}
}
/**
* Compile the HAVING clause for a query.
*
* @param Query $query
* @return string
*/
protected
function
havings
(
Query
$query
)
{
if
(
is_null
(
$query
->
havings
))
return
''
;
foreach
(
$query
->
havings
as
$having
)
{
$sql
[]
=
'AND '
.
$this
->
wrap
(
$having
[
'column'
])
.
' '
.
$having
[
'operator'
]
.
' '
.
$this
->
parameter
(
$having
[
'value'
]);
}
return
'HAVING '
.
preg_replace
(
'/AND /'
,
''
,
implode
(
' '
,
$sql
),
1
);
}
/**
/**
* Compile the ORDER BY clause for a query.
* Compile the ORDER BY clause for a query.
*
*
...
...
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