Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
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
sinan
laravel-mongodb
Commits
9737b9bb
Commit
9737b9bb
authored
Sep 14, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move hybrid relation logic to its own trait
parent
6460d584
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
426 additions
and
448 deletions
+426
-448
Model.php
src/Jenssegers/Eloquent/Model.php
+2
-280
Connection.php
src/Jenssegers/Mongodb/Connection.php
+2
-5
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+9
-9
Collection.php
src/Jenssegers/Mongodb/Eloquent/Collection.php
+1
-1
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+268
-0
Model.php
src/Jenssegers/Mongodb/Model.php
+26
-12
MongodbServiceProvider.php
src/Jenssegers/Mongodb/MongodbServiceProvider.php
+0
-4
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+74
-77
BelongsTo.php
src/Jenssegers/Mongodb/Relations/BelongsTo.php
+0
-3
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+13
-18
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+9
-10
EmbedsOne.php
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
+2
-2
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+8
-12
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+0
-2
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+11
-12
Builder.php
src/Jenssegers/Mongodb/Schema/Builder.php
+1
-1
No files found.
src/Jenssegers/Eloquent/Model.php
View file @
9737b9bb
This diff is collapsed.
Click to expand it.
src/Jenssegers/Mongodb/Connection.php
View file @
9737b9bb
...
@@ -22,7 +22,6 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -22,7 +22,6 @@ class Connection extends \Illuminate\Database\Connection {
* Create a new database connection instance.
* Create a new database connection instance.
*
*
* @param array $config
* @param array $config
* @return void
*/
*/
public
function
__construct
(
array
$config
)
public
function
__construct
(
array
$config
)
{
{
...
@@ -143,7 +142,7 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -143,7 +142,7 @@ class Connection extends \Illuminate\Database\Connection {
}
}
// By default driver options is an empty array.
// By default driver options is an empty array.
$driverOptions
=
array
()
;
$driverOptions
=
[]
;
if
(
isset
(
$config
[
'driver_options'
])
&&
is_array
(
$config
[
'driver_options'
]))
if
(
isset
(
$config
[
'driver_options'
])
&&
is_array
(
$config
[
'driver_options'
]))
{
{
...
@@ -155,8 +154,6 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -155,8 +154,6 @@ class Connection extends \Illuminate\Database\Connection {
/**
/**
* Disconnect from the underlying MongoClient connection.
* Disconnect from the underlying MongoClient connection.
*
* @return void
*/
*/
public
function
disconnect
()
public
function
disconnect
()
{
{
...
@@ -229,7 +226,7 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -229,7 +226,7 @@ class Connection extends \Illuminate\Database\Connection {
*/
*/
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
return
call_user_func_array
(
array
(
$this
->
db
,
$method
)
,
$parameters
);
return
call_user_func_array
(
[
$this
->
db
,
$method
]
,
$parameters
);
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
9737b9bb
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
MongoCursor
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Illuminate\Database\Eloquent\Builder
as
EloquentBuilder
;
use
Illuminate\Database\Eloquent\Builder
as
EloquentBuilder
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
MongoCursor
;
class
Builder
extends
EloquentBuilder
{
class
Builder
extends
EloquentBuilder
{
...
@@ -11,10 +11,10 @@ class Builder extends EloquentBuilder {
...
@@ -11,10 +11,10 @@ class Builder extends EloquentBuilder {
*
*
* @var array
* @var array
*/
*/
protected
$passthru
=
array
(
protected
$passthru
=
[
'toSql'
,
'lists'
,
'insert'
,
'insertGetId'
,
'pluck'
,
'toSql'
,
'lists'
,
'insert'
,
'insertGetId'
,
'pluck'
,
'count'
,
'min'
,
'max'
,
'avg'
,
'sum'
,
'exists'
,
'push'
,
'pull'
,
'count'
,
'min'
,
'max'
,
'avg'
,
'sum'
,
'exists'
,
'push'
,
'pull'
,
)
;
]
;
/**
/**
* Update a record in the database.
* Update a record in the database.
...
@@ -104,7 +104,7 @@ class Builder extends EloquentBuilder {
...
@@ -104,7 +104,7 @@ class Builder extends EloquentBuilder {
* @param array $extra
* @param array $extra
* @return int
* @return int
*/
*/
public
function
increment
(
$column
,
$amount
=
1
,
array
$extra
=
array
()
)
public
function
increment
(
$column
,
$amount
=
1
,
array
$extra
=
[]
)
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
...
@@ -119,7 +119,7 @@ class Builder extends EloquentBuilder {
...
@@ -119,7 +119,7 @@ class Builder extends EloquentBuilder {
$this
->
model
->
syncOriginalAttribute
(
$column
);
$this
->
model
->
syncOriginalAttribute
(
$column
);
$result
=
$this
->
model
->
update
(
array
(
$column
=>
$value
)
);
$result
=
$this
->
model
->
update
(
[
$column
=>
$value
]
);
return
$result
;
return
$result
;
}
}
...
@@ -135,7 +135,7 @@ class Builder extends EloquentBuilder {
...
@@ -135,7 +135,7 @@ class Builder extends EloquentBuilder {
* @param array $extra
* @param array $extra
* @return int
* @return int
*/
*/
public
function
decrement
(
$column
,
$amount
=
1
,
array
$extra
=
array
()
)
public
function
decrement
(
$column
,
$amount
=
1
,
array
$extra
=
[]
)
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
...
@@ -150,7 +150,7 @@ class Builder extends EloquentBuilder {
...
@@ -150,7 +150,7 @@ class Builder extends EloquentBuilder {
$this
->
model
->
syncOriginalAttribute
(
$column
);
$this
->
model
->
syncOriginalAttribute
(
$column
);
return
$this
->
model
->
update
(
array
(
$column
=>
$value
)
);
return
$this
->
model
->
update
(
[
$column
=>
$value
]
);
}
}
return
parent
::
decrement
(
$column
,
$amount
,
$extra
);
return
parent
::
decrement
(
$column
,
$amount
,
$extra
);
...
@@ -194,7 +194,7 @@ class Builder extends EloquentBuilder {
...
@@ -194,7 +194,7 @@ class Builder extends EloquentBuilder {
});
});
// If the operator is <, <= or !=, we will use whereNotIn.
// If the operator is <, <= or !=, we will use whereNotIn.
$not
=
in_array
(
$operator
,
array
(
'<'
,
'<='
,
'!='
)
);
$not
=
in_array
(
$operator
,
[
'<'
,
'<='
,
'!='
]
);
// If we are comparing to 0, we need an additional $not flip.
// If we are comparing to 0, we need an additional $not flip.
if
(
$count
==
0
)
$not
=
!
$not
;
if
(
$count
==
0
)
$not
=
!
$not
;
...
...
src/Jenssegers/Mongodb/Eloquent/Collection.php
View file @
9737b9bb
...
@@ -37,7 +37,7 @@ class Collection extends EloquentCollection {
...
@@ -37,7 +37,7 @@ class Collection extends EloquentCollection {
// and keep going.
// and keep going.
if
(
func_num_args
()
==
2
)
if
(
func_num_args
()
==
2
)
{
{
list
(
$value
,
$operator
)
=
array
(
$operator
,
'='
)
;
list
(
$value
,
$operator
)
=
[
$operator
,
'='
]
;
}
}
return
$this
->
filter
(
function
(
$item
)
use
(
$key
,
$operator
,
$value
)
return
$this
->
filter
(
function
(
$item
)
use
(
$key
,
$operator
,
$value
)
...
...
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
0 → 100644
View file @
9737b9bb
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
Illuminate\Database\Eloquent\Relations\MorphMany
;
use
Illuminate\Database\Eloquent\Relations\MorphOne
;
use
Jenssegers\Mongodb\Model
;
use
Jenssegers\Mongodb\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Relations\BelongsToMany
;
use
Jenssegers\Mongodb\Relations\HasMany
;
use
Jenssegers\Mongodb\Relations\HasOne
;
use
Jenssegers\Mongodb\Relations\MorphTo
;
trait
HybridRelations
{
/**
* Define a one-to-one relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
}
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
();
$instance
=
new
$related
;
$localKey
=
$localKey
?:
$this
->
getKeyName
();
return
new
HasOne
(
$instance
->
newQuery
(),
$this
,
$foreignKey
,
$localKey
);
}
/**
* Define a polymorphic one-to-one relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
$instance
=
new
$related
;
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
$table
=
$instance
->
getTable
();
$localKey
=
$localKey
?:
$this
->
getKeyName
();
return
new
MorphOne
(
$instance
->
newQuery
(),
$this
,
$type
,
$id
,
$localKey
);
}
/**
* Define a one-to-many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
}
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
();
$instance
=
new
$related
;
$localKey
=
$localKey
?:
$this
->
getKeyName
();
return
new
HasMany
(
$instance
->
newQuery
(),
$this
,
$foreignKey
,
$localKey
);
}
/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
$instance
=
new
$related
;
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
$table
=
$instance
->
getTable
();
$localKey
=
$localKey
?:
$this
->
getKeyName
();
return
new
MorphMany
(
$instance
->
newQuery
(),
$this
,
$type
,
$id
,
$localKey
);
}
/**
* Define an inverse one-to-one or many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
belongsTo
(
$related
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships.
if
(
is_null
(
$relation
))
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
}
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
))
{
$foreignKey
=
snake_case
(
$relation
)
.
'_id'
;
}
$instance
=
new
$related
;
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$query
=
$instance
->
newQuery
();
$otherKey
=
$otherKey
?:
$instance
->
getKeyName
();
return
new
BelongsTo
(
$query
,
$this
,
$foreignKey
,
$otherKey
,
$relation
);
}
/**
* Define a polymorphic, inverse one-to-one or many relationship.
*
* @param string $name
* @param string $type
* @param string $id
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public
function
morphTo
(
$name
=
null
,
$type
=
null
,
$id
=
null
)
{
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if
(
is_null
(
$name
))
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
$name
=
snake_case
(
$caller
[
'function'
]);
}
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
if
(
is_null
(
$class
=
$this
->
$type
))
{
return
new
MorphTo
(
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
);
}
// If we are not eager loading the relatinship, we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else
{
$instance
=
new
$class
;
return
new
MorphTo
(
with
(
$instance
)
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
}
}
/**
* Define a many-to-many relationship.
*
* @param string $related
* @param string $collection
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public
function
belongsToMany
(
$related
,
$collection
=
null
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
{
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
if
(
is_null
(
$relation
))
{
$relation
=
$this
->
getBelongsToManyCaller
();
}
// Check if it is a relation with an original model.
if
(
$related
instanceof
Model
)
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
()
.
's'
;
$instance
=
new
$related
;
$otherKey
=
$otherKey
?:
$instance
->
getForeignKey
()
.
's'
;
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if
(
is_null
(
$collection
))
{
$collection
=
$instance
->
getTable
();
}
// Now we're ready to create a new query builder for the related model and
// the relationship instances for the relation. The relations will set
// appropriate query constraint and entirely manages the hydrations.
$query
=
$instance
->
newQuery
();
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
src/Jenssegers/Mongodb/Model.php
View file @
9737b9bb
...
@@ -2,16 +2,21 @@
...
@@ -2,16 +2,21 @@
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
DateTime
;
use
DateTime
;
use
MongoDate
;
use
Illuminate\Database\Eloquent\Model
as
BaseModel
;
use
MongoId
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Query\Builder
as
QueryBuilder
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
use
Jenssegers\Mongodb\Relations\EmbedsOne
;
use
Jenssegers\Mongodb\Relations\EmbedsOne
;
use
Jenssegers\Mongodb\Relations\EmbedsOneOrMany
;
use
Jenssegers\Mongodb\Relations\EmbedsOneOrMany
;
use
MongoDate
;
use
MongoId
;
use
ReflectionMethod
;
use
ReflectionMethod
;
abstract
class
Model
extends
\Jenssegers\Eloquent\Model
{
abstract
class
Model
extends
BaseModel
{
use
HybridRelations
;
/**
/**
* The collection associated with the model.
* The collection associated with the model.
...
@@ -292,7 +297,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -292,7 +297,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
*
* @param string $key
* @param string $key
* @param mixed $value
* @param mixed $value
* @return void
*/
*/
public
function
setAttribute
(
$key
,
$value
)
public
function
setAttribute
(
$key
,
$value
)
{
{
...
@@ -361,7 +365,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -361,7 +365,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
$columns
=
array
(
$columns
)
;
if
(
!
is_array
(
$columns
))
$columns
=
[
$columns
]
;
// Unset attributes
// Unset attributes
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
...
@@ -394,7 +398,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -394,7 +398,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
}
}
// Do batch push by default.
// Do batch push by default.
if
(
!
is_array
(
$values
))
$values
=
array
(
$values
)
;
if
(
!
is_array
(
$values
))
$values
=
[
$values
]
;
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
...
@@ -416,7 +420,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -416,7 +420,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
public
function
pull
(
$column
,
$values
)
public
function
pull
(
$column
,
$values
)
{
{
// Do batch pull by default.
// Do batch pull by default.
if
(
!
is_array
(
$values
))
$values
=
array
(
$values
)
;
if
(
!
is_array
(
$values
))
$values
=
[
$values
]
;
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
...
@@ -431,11 +435,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -431,11 +435,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
* @param string $column
* @param string $column
* @param array $values
* @param array $values
* @param bool $unique
* @param bool $unique
* @return void
*/
*/
protected
function
pushAttributeValues
(
$column
,
array
$values
,
$unique
=
false
)
protected
function
pushAttributeValues
(
$column
,
array
$values
,
$unique
=
false
)
{
{
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
array
()
;
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[]
;
foreach
(
$values
as
$value
)
foreach
(
$values
as
$value
)
{
{
...
@@ -455,11 +458,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -455,11 +458,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
*
* @param string $column
* @param string $column
* @param array $values
* @param array $values
* @return void
*/
*/
protected
function
pullAttributeValues
(
$column
,
array
$values
)
protected
function
pullAttributeValues
(
$column
,
array
$values
)
{
{
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
array
()
;
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[]
;
foreach
(
$values
as
$value
)
foreach
(
$values
as
$value
)
{
{
...
@@ -507,6 +509,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -507,6 +509,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
return
new
Builder
(
$query
);
return
new
Builder
(
$query
);
}
}
/**
* Get a new query builder instance for the connection.
*
* @return Builder
*/
protected
function
newBaseQueryBuilder
()
{
$connection
=
$this
->
getConnection
();
return
new
QueryBuilder
(
$connection
,
$connection
->
getPostProcessor
());
}
/**
/**
* Handle dynamic method calls into the method.
* Handle dynamic method calls into the method.
*
*
...
@@ -519,7 +533,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -519,7 +533,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
// Unset method
// Unset method
if
(
$method
==
'unset'
)
if
(
$method
==
'unset'
)
{
{
return
call_user_func_array
(
array
(
$this
,
'drop'
)
,
$parameters
);
return
call_user_func_array
(
[
$this
,
'drop'
]
,
$parameters
);
}
}
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
...
...
src/Jenssegers/Mongodb/MongodbServiceProvider.php
View file @
9737b9bb
...
@@ -6,8 +6,6 @@ class MongodbServiceProvider extends ServiceProvider {
...
@@ -6,8 +6,6 @@ class MongodbServiceProvider extends ServiceProvider {
/**
/**
* Bootstrap the application events.
* Bootstrap the application events.
*
* @return void
*/
*/
public
function
boot
()
public
function
boot
()
{
{
...
@@ -18,8 +16,6 @@ class MongodbServiceProvider extends ServiceProvider {
...
@@ -18,8 +16,6 @@ class MongodbServiceProvider extends ServiceProvider {
/**
/**
* Register the service provider.
* Register the service provider.
*
* @return void
*/
*/
public
function
register
()
public
function
register
()
{
{
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
9737b9bb
This diff is collapsed.
Click to expand it.
src/Jenssegers/Mongodb/Relations/BelongsTo.php
View file @
9737b9bb
...
@@ -4,8 +4,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
...
@@ -4,8 +4,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*
* @return void
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
...
@@ -22,7 +20,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
...
@@ -22,7 +20,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
* Set the constraints for an eager load of the relation.
* Set the constraints for an eager load of the relation.
*
*
* @param array $models
* @param array $models
* @return void
*/
*/
public
function
addEagerConstraints
(
array
$models
)
public
function
addEagerConstraints
(
array
$models
)
{
{
...
...
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
9737b9bb
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
as
EloquentBelongsToMany
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
as
EloquentBelongsToMany
;
class
BelongsToMany
extends
EloquentBelongsToMany
{
class
BelongsToMany
extends
EloquentBelongsToMany
{
...
@@ -10,7 +10,6 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -10,7 +10,6 @@ class BelongsToMany extends EloquentBelongsToMany {
* Hydrate the pivot table relationship on the models.
* Hydrate the pivot table relationship on the models.
*
*
* @param array $models
* @param array $models
* @return void
*/
*/
protected
function
hydratePivotRelation
(
array
$models
)
protected
function
hydratePivotRelation
(
array
$models
)
{
{
...
@@ -23,15 +22,13 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -23,15 +22,13 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param array $columns
* @param array $columns
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
*/
protected
function
getSelectColumns
(
array
$columns
=
array
(
'*'
)
)
protected
function
getSelectColumns
(
array
$columns
=
[
'*'
]
)
{
{
return
$columns
;
return
$columns
;
}
}
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*
* @return void
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
...
@@ -60,9 +57,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -60,9 +57,9 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model
*/
*/
public
function
save
(
Model
$model
,
array
$joining
=
array
()
,
$touch
=
true
)
public
function
save
(
Model
$model
,
array
$joining
=
[]
,
$touch
=
true
)
{
{
$model
->
save
(
array
(
'touch'
=>
false
)
);
$model
->
save
(
[
'touch'
=>
false
]
);
$this
->
attach
(
$model
,
$joining
,
$touch
);
$this
->
attach
(
$model
,
$joining
,
$touch
);
...
@@ -77,14 +74,14 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -77,14 +74,14 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model
*/
*/
public
function
create
(
array
$attributes
,
array
$joining
=
array
()
,
$touch
=
true
)
public
function
create
(
array
$attributes
,
array
$joining
=
[]
,
$touch
=
true
)
{
{
$instance
=
$this
->
related
->
newInstance
(
$attributes
);
$instance
=
$this
->
related
->
newInstance
(
$attributes
);
// Once we save the related model, we need to attach it to the base model via
// Once we save the related model, we need to attach it to the base model via
// through intermediate table so we'll use the existing "attach" method to
// through intermediate table so we'll use the existing "attach" method to
// accomplish this which will insert the record and any more attributes.
// accomplish this which will insert the record and any more attributes.
$instance
->
save
(
array
(
'touch'
=>
false
)
);
$instance
->
save
(
[
'touch'
=>
false
]
);
$this
->
attach
(
$instance
,
$joining
,
$touch
);
$this
->
attach
(
$instance
,
$joining
,
$touch
);
...
@@ -100,16 +97,16 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -100,16 +97,16 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
public
function
sync
(
$ids
,
$detaching
=
true
)
public
function
sync
(
$ids
,
$detaching
=
true
)
{
{
$changes
=
array
(
$changes
=
[
'attached'
=>
array
(),
'detached'
=>
array
(),
'updated'
=>
array
()
,
'attached'
=>
[],
'detached'
=>
[],
'updated'
=>
[]
,
)
;
]
;
if
(
$ids
instanceof
Collection
)
$ids
=
$ids
->
modelKeys
();
if
(
$ids
instanceof
Collection
)
$ids
=
$ids
->
modelKeys
();
// First we need to attach any of the associated models that are not currently
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
// if they exist in the array of current ones, and if not we will insert.
$current
=
$this
->
parent
->
{
$this
->
otherKey
}
?:
array
()
;
$current
=
$this
->
parent
->
{
$this
->
otherKey
}
?:
[]
;
// See issue #256.
// See issue #256.
if
(
$current
instanceof
Collection
)
$current
=
$ids
->
modelKeys
();
if
(
$current
instanceof
Collection
)
$current
=
$ids
->
modelKeys
();
...
@@ -153,7 +150,6 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -153,7 +150,6 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param mixed $id
* @param mixed $id
* @param array $attributes
* @param array $attributes
* @param bool $touch
* @param bool $touch
* @return void
*/
*/
public
function
updateExistingPivot
(
$id
,
array
$attributes
,
$touch
=
true
)
public
function
updateExistingPivot
(
$id
,
array
$attributes
,
$touch
=
true
)
{
{
...
@@ -166,9 +162,8 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -166,9 +162,8 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param mixed $id
* @param mixed $id
* @param array $attributes
* @param array $attributes
* @param bool $touch
* @param bool $touch
* @return void
*/
*/
public
function
attach
(
$id
,
array
$attributes
=
array
()
,
$touch
=
true
)
public
function
attach
(
$id
,
array
$attributes
=
[]
,
$touch
=
true
)
{
{
if
(
$id
instanceof
Model
)
if
(
$id
instanceof
Model
)
{
{
...
@@ -202,7 +197,7 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -202,7 +197,7 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @param bool $touch
* @return int
* @return int
*/
*/
public
function
detach
(
$ids
=
array
()
,
$touch
=
true
)
public
function
detach
(
$ids
=
[]
,
$touch
=
true
)
{
{
if
(
$ids
instanceof
Model
)
$ids
=
(
array
)
$ids
->
getKey
();
if
(
$ids
instanceof
Model
)
$ids
=
(
array
)
$ids
->
getKey
();
...
@@ -243,7 +238,7 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -243,7 +238,7 @@ class BelongsToMany extends EloquentBelongsToMany {
// First we will build a dictionary of child models keyed by the foreign key
// First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their
// of the relation so that we will easily and quickly match them to their
// parents without having a possibly slow inner loops for every models.
// parents without having a possibly slow inner loops for every models.
$dictionary
=
array
()
;
$dictionary
=
[]
;
foreach
(
$results
as
$result
)
foreach
(
$results
as
$result
)
{
{
...
...
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
9737b9bb
...
@@ -99,7 +99,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -99,7 +99,7 @@ class EmbedsMany extends EmbedsOneOrMany {
// Get the correct foreign key value.
// Get the correct foreign key value.
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
$result
=
$this
->
getBaseQuery
()
->
pull
(
$this
->
localKey
,
array
(
$model
->
getKeyName
()
=>
$foreignKey
)
);
$result
=
$this
->
getBaseQuery
()
->
pull
(
$this
->
localKey
,
[
$model
->
getKeyName
()
=>
$foreignKey
]
);
if
(
$result
)
$this
->
dissociate
(
$model
);
if
(
$result
)
$this
->
dissociate
(
$model
);
...
@@ -130,7 +130,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -130,7 +130,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @param mixed $ids
* @return int
* @return int
*/
*/
public
function
dissociate
(
$ids
=
array
()
)
public
function
dissociate
(
$ids
=
[]
)
{
{
$ids
=
$this
->
getIdsArrayFrom
(
$ids
);
$ids
=
$this
->
getIdsArrayFrom
(
$ids
);
...
@@ -161,7 +161,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -161,7 +161,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @param mixed $ids
* @return int
* @return int
*/
*/
public
function
destroy
(
$ids
=
array
()
)
public
function
destroy
(
$ids
=
[]
)
{
{
$count
=
0
;
$count
=
0
;
...
@@ -187,9 +187,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -187,9 +187,9 @@ class EmbedsMany extends EmbedsOneOrMany {
public
function
delete
()
public
function
delete
()
{
{
// Overwrite the local key with an empty array.
// Overwrite the local key with an empty array.
$result
=
$this
->
query
->
update
(
array
(
$this
->
localKey
=>
array
())
);
$result
=
$this
->
query
->
update
(
[
$this
->
localKey
=>
[]]
);
if
(
$result
)
$this
->
setEmbedded
(
array
()
);
if
(
$result
)
$this
->
setEmbedded
(
[]
);
return
$result
;
return
$result
;
}
}
...
@@ -200,7 +200,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -200,7 +200,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @param mixed $ids
* @return int
* @return int
*/
*/
public
function
detach
(
$ids
=
array
()
)
public
function
detach
(
$ids
=
[]
)
{
{
return
$this
->
destroy
(
$ids
);
return
$this
->
destroy
(
$ids
);
}
}
...
@@ -296,18 +296,17 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -296,18 +296,17 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
*/
protected
function
getEmbedded
()
protected
function
getEmbedded
()
{
{
return
parent
::
getEmbedded
()
?:
array
()
;
return
parent
::
getEmbedded
()
?:
[]
;
}
}
/**
/**
* Set the embedded records array.
* Set the embedded records array.
*
*
* @param array $models
* @param array $models
* @return void
*/
*/
protected
function
setEmbedded
(
$models
)
protected
function
setEmbedded
(
$models
)
{
{
if
(
!
is_array
(
$models
))
$models
=
array
(
$models
)
;
if
(
!
is_array
(
$models
))
$models
=
[
$models
]
;
return
parent
::
setEmbedded
(
array_values
(
$models
));
return
parent
::
setEmbedded
(
array_values
(
$models
));
}
}
...
@@ -324,7 +323,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -324,7 +323,7 @@ class EmbedsMany extends EmbedsOneOrMany {
// Collection methods
// Collection methods
if
(
method_exists
(
'Jenssegers\Mongodb\Eloquent\Collection'
,
$method
))
if
(
method_exists
(
'Jenssegers\Mongodb\Eloquent\Collection'
,
$method
))
{
{
return
call_user_func_array
(
array
(
$this
->
getResults
(),
$method
)
,
$parameters
);
return
call_user_func_array
(
[
$this
->
getResults
(),
$method
]
,
$parameters
);
}
}
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
View file @
9737b9bb
...
@@ -37,7 +37,7 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -37,7 +37,7 @@ class EmbedsOne extends EmbedsOneOrMany {
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
}
}
$result
=
$this
->
getBaseQuery
()
->
update
(
array
(
$this
->
localKey
=>
$model
->
getAttributes
())
);
$result
=
$this
->
getBaseQuery
()
->
update
(
[
$this
->
localKey
=>
$model
->
getAttributes
()]
);
// Attach the model to its parent.
// Attach the model to its parent.
if
(
$result
)
$this
->
associate
(
$model
);
if
(
$result
)
$this
->
associate
(
$model
);
...
@@ -88,7 +88,7 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -88,7 +88,7 @@ class EmbedsOne extends EmbedsOneOrMany {
}
}
// Overwrite the local key with an empty array.
// Overwrite the local key with an empty array.
$result
=
$this
->
getBaseQuery
()
->
update
(
array
(
$this
->
localKey
=>
null
)
);
$result
=
$this
->
getBaseQuery
()
->
update
(
[
$this
->
localKey
=>
null
]
);
// Detach the model from its parent.
// Detach the model from its parent.
if
(
$result
)
$this
->
dissociate
();
if
(
$result
)
$this
->
dissociate
();
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
9737b9bb
...
@@ -59,8 +59,6 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -59,8 +59,6 @@ abstract class EmbedsOneOrMany extends Relation {
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*
* @return void
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
...
@@ -74,7 +72,6 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -74,7 +72,6 @@ abstract class EmbedsOneOrMany extends Relation {
* Set the constraints for an eager load of the relation.
* Set the constraints for an eager load of the relation.
*
*
* @param array $models
* @param array $models
* @return void
*/
*/
public
function
addEagerConstraints
(
array
$models
)
public
function
addEagerConstraints
(
array
$models
)
{
{
...
@@ -86,7 +83,6 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -86,7 +83,6 @@ abstract class EmbedsOneOrMany extends Relation {
*
*
* @param array $models
* @param array $models
* @param string $relation
* @param string $relation
* @return void
*/
*/
public
function
initRelation
(
array
$models
,
$relation
)
public
function
initRelation
(
array
$models
,
$relation
)
{
{
...
@@ -166,7 +162,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -166,7 +162,7 @@ abstract class EmbedsOneOrMany extends Relation {
foreach
(
$models
as
$model
)
{
foreach
(
$models
as
$model
)
{
$this
->
save
(
$model
);
$this
->
save
(
$model
);
}
}
return
$models
;
return
$models
;
}
}
...
@@ -198,7 +194,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -198,7 +194,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
public
function
createMany
(
array
$records
)
public
function
createMany
(
array
$records
)
{
{
$instances
=
array
()
;
$instances
=
[]
;
foreach
(
$records
as
$record
)
foreach
(
$records
as
$record
)
{
{
...
@@ -216,7 +212,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -216,7 +212,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
protected
function
getIdsArrayFrom
(
$ids
)
protected
function
getIdsArrayFrom
(
$ids
)
{
{
if
(
!
is_array
(
$ids
))
$ids
=
array
(
$ids
)
;
if
(
!
is_array
(
$ids
))
$ids
=
[
$ids
]
;
foreach
(
$ids
as
&
$id
)
foreach
(
$ids
as
&
$id
)
{
{
...
@@ -281,9 +277,9 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -281,9 +277,9 @@ abstract class EmbedsOneOrMany extends Relation {
* @param array $records
* @param array $records
* @return \Jenssegers\Mongodb\Eloquent\Collection
* @return \Jenssegers\Mongodb\Eloquent\Collection
*/
*/
protected
function
toCollection
(
array
$records
=
array
()
)
protected
function
toCollection
(
array
$records
=
[]
)
{
{
$models
=
array
()
;
$models
=
[]
;
foreach
(
$records
as
$attributes
)
foreach
(
$records
as
$attributes
)
{
{
...
@@ -304,7 +300,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -304,7 +300,7 @@ abstract class EmbedsOneOrMany extends Relation {
* @param array $attributes
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model
*/
*/
protected
function
toModel
(
$attributes
=
array
()
)
protected
function
toModel
(
$attributes
=
[]
)
{
{
if
(
is_null
(
$attributes
))
return
;
if
(
is_null
(
$attributes
))
return
;
...
@@ -315,7 +311,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -315,7 +311,7 @@ abstract class EmbedsOneOrMany extends Relation {
$model
->
setRelation
(
$this
->
foreignKey
,
$this
->
parent
);
$model
->
setRelation
(
$this
->
foreignKey
,
$this
->
parent
);
// If you remove this, you will get segmentation faults!
// If you remove this, you will get segmentation faults!
$model
->
setHidden
(
array_merge
(
$model
->
getHidden
(),
array
(
$this
->
foreignKey
)
));
$model
->
setHidden
(
array_merge
(
$model
->
getHidden
(),
[
$this
->
foreignKey
]
));
return
$model
;
return
$model
;
}
}
...
@@ -357,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -357,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation {
/**
/**
* Check if this relation is nested in another relation.
* Check if this relation is nested in another relation.
*
*
* @return bool
ean
* @return bool
*/
*/
protected
function
isNested
()
protected
function
isNested
()
{
{
...
...
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
9737b9bb
...
@@ -6,8 +6,6 @@ class MorphTo extends EloquentMorphTo {
...
@@ -6,8 +6,6 @@ class MorphTo extends EloquentMorphTo {
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*
* @return void
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
...
...
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
9737b9bb
...
@@ -24,14 +24,13 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -24,14 +24,13 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
*
*
* @var array
* @var array
*/
*/
protected
$columns
=
array
()
;
protected
$columns
=
[]
;
/**
/**
* Create a new schema blueprint.
* Create a new schema blueprint.
*
*
* @param string $table
* @param string $table
* @param Closure $callback
* @param Closure $callback
* @return void
*/
*/
public
function
__construct
(
Connection
$connection
,
$collection
)
public
function
__construct
(
Connection
$connection
,
$collection
)
{
{
...
@@ -47,7 +46,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -47,7 +46,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $options
* @param array $options
* @return Blueprint
* @return Blueprint
*/
*/
public
function
index
(
$columns
=
null
,
$options
=
array
()
)
public
function
index
(
$columns
=
null
,
$options
=
[]
)
{
{
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
...
@@ -55,7 +54,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -55,7 +54,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
{
// Transform the columns to the required array format.
// Transform the columns to the required array format.
$transform
=
array
()
;
$transform
=
[]
;
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
...
@@ -77,7 +76,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -77,7 +76,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $options
* @param array $options
* @return \Illuminate\Support\Fluent
* @return \Illuminate\Support\Fluent
*/
*/
public
function
primary
(
$columns
=
null
,
$options
=
array
()
)
public
function
primary
(
$columns
=
null
,
$options
=
[]
)
{
{
return
$this
->
unique
(
$columns
,
$options
);
return
$this
->
unique
(
$columns
,
$options
);
}
}
...
@@ -96,7 +95,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -96,7 +95,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
{
// Transform the columns to the required array format.
// Transform the columns to the required array format.
$transform
=
array
()
;
$transform
=
[]
;
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
...
@@ -121,7 +120,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -121,7 +120,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
{
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
$this
->
index
(
$columns
,
array
(
'unique'
=>
true
)
);
$this
->
index
(
$columns
,
[
'unique'
=>
true
]
);
return
$this
;
return
$this
;
}
}
...
@@ -136,7 +135,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -136,7 +135,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
{
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
$this
->
index
(
$columns
,
array
(
'background'
=>
true
)
);
$this
->
index
(
$columns
,
[
'background'
=>
true
]
);
return
$this
;
return
$this
;
}
}
...
@@ -150,7 +149,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -150,7 +149,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
public
function
sparse
(
$columns
=
null
)
public
function
sparse
(
$columns
=
null
)
{
{
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
$this
->
index
(
$columns
,
array
(
'sparse'
=>
true
)
);
$this
->
index
(
$columns
,
[
'sparse'
=>
true
]
);
return
$this
;
return
$this
;
}
}
...
@@ -167,7 +166,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -167,7 +166,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
{
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
$this
->
index
(
$columns
,
array
(
'expireAfterSeconds'
=>
$seconds
)
);
$this
->
index
(
$columns
,
[
'expireAfterSeconds'
=>
$seconds
]
);
return
$this
;
return
$this
;
}
}
...
@@ -205,7 +204,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -205,7 +204,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $parameters
* @param array $parameters
* @return Blueprint
* @return Blueprint
*/
*/
protected
function
addColumn
(
$type
,
$name
,
array
$parameters
=
array
()
)
protected
function
addColumn
(
$type
,
$name
,
array
$parameters
=
[]
)
{
{
$this
->
fluent
(
$name
);
$this
->
fluent
(
$name
);
...
@@ -226,7 +225,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -226,7 +225,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
}
}
elseif
(
is_string
(
$columns
))
elseif
(
is_string
(
$columns
))
{
{
return
$this
->
columns
=
array
(
$columns
)
;
return
$this
->
columns
=
[
$columns
]
;
}
}
else
else
{
{
...
...
src/Jenssegers/Mongodb/Schema/Builder.php
View file @
9737b9bb
...
@@ -14,7 +14,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
...
@@ -14,7 +14,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
{
$this
->
connection
=
$connection
;
$this
->
connection
=
$connection
;
}
}
/**
/**
* Determine if the given table has a given column.
* Determine if the given table has a given column.
*
*
...
...
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