From 84ee385dbcdf9d5a124e99479103d5b672946d44 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 12 Dec 2013 07:23:06 -0600 Subject: [PATCH 001/577] Fix dependencies. --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 4f05bc08c..bb889fd6b 100755 --- a/composer.json +++ b/composer.json @@ -10,17 +10,17 @@ ], "require": { "php": ">=5.3.0", - "illuminate/container": "4.1.x", - "illuminate/events": "4.1.x", - "illuminate/support": "4.1.x", + "illuminate/container": "4.2.*", + "illuminate/events": "4.2.*", + "illuminate/support": "4.2.*", "nesbot/carbon": "1.*" }, "require-dev": { - "illuminate/cache": "4.1.x", - "illuminate/console": "4.1.x", - "illuminate/filesystem": "4.1.x", - "illuminate/pagination": "4.1.x", - "illuminate/support": "4.1.x", + "illuminate/cache": "4.2.*", + "illuminate/console": "4.2.*", + "illuminate/filesystem": "4.2.*", + "illuminate/pagination": "4.2.*", + "illuminate/support": "4.2.*", "mockery/mockery": "0.7.2", "phpunit/phpunit": "3.7.*" }, From d92b8c312eb1778baacac8d5390fea0fa8e5351b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 12 Dec 2013 20:00:38 -0600 Subject: [PATCH 002/577] Model::destroy now returns the total number of records deleted. --- Eloquent/Model.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 40997c2d2..bf0164800 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -884,10 +884,15 @@ public function joiningTable($related) * Destroy the models for the given IDs. * * @param array|int $ids - * @return void + * @return int */ public static function destroy($ids) { + // We'll initialize a count here so we will return the total number of deletes + // for the operation. The developers can then check this number as a boolean + // type value or get this total count of records deleted for logging, etc. + $count = 0; + $ids = is_array($ids) ? $ids : func_get_args(); $instance = new static; @@ -899,8 +904,10 @@ public static function destroy($ids) foreach ($instance->whereIn($key, $ids)->get() as $model) { - $model->delete(); + if ($model->delete()) $count++; } + + return $count; } /** From 5eb406cf123ea57093d1b3c2360ed299290ee859 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 12 Dec 2013 20:02:13 -0600 Subject: [PATCH 003/577] Fix typo. --- QueryException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QueryException.php b/QueryException.php index 57822d19c..5ede1b3e0 100644 --- a/QueryException.php +++ b/QueryException.php @@ -17,7 +17,7 @@ class QueryException extends \PDOException { protected $bindings; /** - * Create a new query excetion instance. + * Create a new query exception instance. * * @param string $sql * @param array $bindings From 5408610879412bf34ae09be981c54671058ec947 Mon Sep 17 00:00:00 2001 From: crynobone Date: Fri, 13 Dec 2013 10:49:39 +0800 Subject: [PATCH 004/577] Update components branch alias for dev-master. Signed-off-by: crynobone --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bb889fd6b..f56a54bec 100755 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "target-dir": "Illuminate/Database", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "minimum-stability": "dev" From c6f225fcb069e2f8d3033c458b6a23cc343494f0 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Tue, 17 Dec 2013 10:45:45 +0100 Subject: [PATCH 005/577] Parent key methods visiblity --- Eloquent/Relations/HasOneOrMany.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 9d2664540..2bd695063 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -276,7 +276,7 @@ public function getPlainForeignKey() * * @return mixed */ - protected function getParentKey() + public function getParentKey() { return $this->parent->getAttribute($this->localKey); } @@ -286,7 +286,7 @@ protected function getParentKey() * * @return string */ - protected function getQualifiedParentKeyName() + public function getQualifiedParentKeyName() { return $this->parent->getTable().'.'.$this->localKey; } From d3d71a36adaac5cfca15599cf4dccfeb33e5d001 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 19 Dec 2013 22:13:54 -0500 Subject: [PATCH 006/577] Added support for passing an Eloquent Collection to sync() when inserting on a many-to-many relationship instead of just an array of IDs --- Eloquent/Relations/BelongsToMany.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index a4534379c..3395eb634 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -518,14 +518,19 @@ public function createMany(array $records, array $joinings = array()) } /** - * Sync the intermediate tables with a list of IDs. + * Sync the intermediate tables with a list of IDs or collection of models. * - * @param array $ids + * @param $ids * @param bool $detaching * @return void */ - public function sync(array $ids, $detaching = true) + public function sync($ids, $detaching = true) { + // If we have a collection of models, get the keys. + if ($ids instanceof Collection) { + $ids = $ids->lists($this->otherKey); + } + // 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 // if they exist in the array of current ones, and if not we will insert. From 5927a954abe7ccc8d9454ffe4660bfff1806245e Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 20 Dec 2013 12:29:33 +0100 Subject: [PATCH 007/577] catch PDOException --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index b5ff3fadd..db5f51548 100755 --- a/Connection.php +++ b/Connection.php @@ -534,7 +534,7 @@ protected function run($query, $bindings, Closure $callback) // If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. - catch (\Exception $e) + catch (\PDOException $e) { throw new QueryException($query, $bindings, $e); } From f335510a2f0aff07f4a4926373f15bdfc60683e4 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 20 Dec 2013 12:36:37 +0100 Subject: [PATCH 008/577] improvements --- Connection.php | 2 +- QueryException.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Connection.php b/Connection.php index db5f51548..b5ff3fadd 100755 --- a/Connection.php +++ b/Connection.php @@ -534,7 +534,7 @@ protected function run($query, $bindings, Closure $callback) // If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. - catch (\PDOException $e) + catch (\Exception $e) { throw new QueryException($query, $bindings, $e); } diff --git a/QueryException.php b/QueryException.php index 5ede1b3e0..6b8e0eeb7 100644 --- a/QueryException.php +++ b/QueryException.php @@ -1,6 +1,8 @@ bindings = $bindings; $this->previous = $previous; $this->code = $previous->getCode(); - $this->errorInfo = $previous->errorInfo; $this->message = $this->formatMessage($sql, $bindings, $previous); + + if ($previous instanceof PDOException) + { + $this->errorInfo = $previous->errorInfo; + } } /** From e35229072ec17831132879431b1880b5d990e989 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 20 Dec 2013 12:54:26 +0100 Subject: [PATCH 009/577] correct docblock --- QueryException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QueryException.php b/QueryException.php index 6b8e0eeb7..4146d9cad 100644 --- a/QueryException.php +++ b/QueryException.php @@ -45,7 +45,7 @@ public function __construct($sql, array $bindings, $previous) * * @param string $sql * @param array $bindings - * @param \PDOException $previous + * @param \Exception $previous * @return string */ protected function formatMessage($sql, $bindings, $previous) From da770f9c2d2262385e7391a28b20f237110756ce Mon Sep 17 00:00:00 2001 From: Youpie Date: Sat, 21 Dec 2013 17:18:18 +0100 Subject: [PATCH 010/577] Fix docblock --- Schema/Grammars/MySqlGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 7de0007d9..78040b5c4 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -98,7 +98,7 @@ protected function compileCreateEncoding($sql, Connection $connection) } /** - * Compile a create table command. + * Compile an add column command. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $command From 8f87d14bbdb99484514002c2f4505129d2147661 Mon Sep 17 00:00:00 2001 From: Kane Cohen Date: Sun, 22 Dec 2013 09:33:38 +0000 Subject: [PATCH 011/577] Fix DB offset method. Can not be negative. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index df4e91ad8..96af6b3a3 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -947,7 +947,7 @@ public function orderByRaw($sql, $bindings = array()) */ public function offset($value) { - $this->offset = $value; + $this->offset = $value > 0 ? $value : 0; return $this; } From 3acdab9720ecd30cdcc873d8778edaf3eff050e7 Mon Sep 17 00:00:00 2001 From: Kane Cohen Date: Sun, 22 Dec 2013 09:56:18 +0000 Subject: [PATCH 012/577] Use max() instead of ternary in DB offset. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 96af6b3a3..57c86e2dd 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -947,7 +947,7 @@ public function orderByRaw($sql, $bindings = array()) */ public function offset($value) { - $this->offset = $value > 0 ? $value : 0; + $this->offset = max(0, $value); return $this; } From a0273446df0ce10e2eedfd9f40ac02fdadc6a1ba Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 26 Dec 2013 12:58:47 +0000 Subject: [PATCH 013/577] Specify query cache driver --- Query/Builder.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index df4e91ad8..5f363cad8 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -148,6 +148,13 @@ class Builder { */ protected $cacheTags; + /** + * The driver for the query cache. + * + * @var string + */ + protected $cacheDriver; + /** * All of the available clause operators. * @@ -1112,6 +1119,19 @@ public function cacheTags($cacheTags) return $this; } + /** + * Indicate that the results, if cached, should use the given cache driver. + * + * @param string $cacheDriver + * @return \Illuminate\Database\Query\Builder|static + */ + public function cacheDriver($cacheDriver) + { + $this->cacheDriver = $cacheDriver; + + return $this; + } + /** * Execute a query for a single record by ID. * @@ -1225,7 +1245,7 @@ public function getCached($columns = array('*')) */ protected function getCache() { - $cache = $this->connection->getCacheManager(); + $cache = $this->connection->getCacheManager()->driver($this->cacheDriver); return $this->cacheTags ? $cache->tags($this->cacheTags) : $cache; } From e67874d76ec7f05ba928dcc209f1c87c6490a121 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 26 Dec 2013 22:39:50 +0000 Subject: [PATCH 014/577] Fix the enum indefinite article --- Schema/Grammars/MySqlGrammar.php | 2 +- Schema/Grammars/SQLiteGrammar.php | 2 +- Schema/Grammars/SqlServerGrammar.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 7de0007d9..1398682e5 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -427,7 +427,7 @@ protected function typeBoolean(Fluent $column) } /** - * Create the column definition for a enum type. + * Create the column definition for an enum type. * * @param \Illuminate\Support\Fluent $column * @return string diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index 32a26491c..09c5176bf 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -437,7 +437,7 @@ protected function typeBoolean(Fluent $column) } /** - * Create the column definition for a enum type. + * Create the column definition for an enum type. * * @param \Illuminate\Support\Fluent $column * @return string diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 68f4179e2..21d1e6941 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -371,7 +371,7 @@ protected function typeBoolean(Fluent $column) } /** - * Create the column definition for a enum type. + * Create the column definition for an enum type. * * @param \Illuminate\Support\Fluent $column * @return string From c75acace15ee71d0192e1a619335a79903b6c9bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Dec 2013 10:08:51 -0600 Subject: [PATCH 015/577] added seeder option to refresh command. --- Console/Migrations/RefreshCommand.php | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 330dc73a4..d6a9542d0 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -35,12 +35,34 @@ public function fire() // them in succession. We'll also see if we need to res-eed the database. $this->call('migrate', array('--database' => $database)); - if ($this->input->getOption('seed')) + if ($this->needsSeeding()) { - $this->call('db:seed', array('--database' => $database)); + $this->runSeeder(); } } + /** + * Determine if the developer has requested database seeding. + * + * @return bool + */ + protected function needsSeeding() + { + return $this->option('seed') || $this->option('seeder'); + } + + /** + * Run the databsae seeder command. + * + * @return void + */ + protected function runSeeder() + { + $class = $this->option('seeder') ?: 'DatabaseSeeder'; + + $this->call('db:seed', array('--database' => $database, '--class' => $class)); + } + /** * Get the console command options. * @@ -52,6 +74,8 @@ protected function getOptions() array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), + + array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder'), ); } From 54f0e2098c0f6f76d85936b07df5bbb34456a5f1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Dec 2013 10:18:22 -0600 Subject: [PATCH 016/577] added period. --- Console/Migrations/RefreshCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index d6a9542d0..b1b6a3ae2 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -75,7 +75,7 @@ protected function getOptions() array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), - array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder'), + array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'), ); } From f2c9de192635fb2f6f27baa1cebf148b0d88f54f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Dec 2013 10:27:08 -0600 Subject: [PATCH 017/577] added cacheDriver method to query builder. --- Query/Builder.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 5f363cad8..88c44d422 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -149,7 +149,7 @@ class Builder { protected $cacheTags; /** - * The driver for the query cache. + * The cache driver to be used. * * @var string */ @@ -1101,9 +1101,7 @@ public function remember($minutes, $key = null) */ public function rememberForever($key = null) { - list($this->cacheMinutes, $this->cacheKey) = array(-1, $key); - - return $this; + return $this->remember(-1, $key); } /** From de569c7cee7f937554d5c18f3e1d07de27f3af8d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Dec 2013 13:35:21 -0600 Subject: [PATCH 018/577] work on eager loading local keys. --- Eloquent/Relations/HasOneOrMany.php | 2 +- Eloquent/Relations/Relation.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 2bd695063..819cb73ee 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -57,7 +57,7 @@ public function addConstraints() */ public function addEagerConstraints(array $models) { - $this->query->whereIn($this->foreignKey, $this->getKeys($models)); + $this->query->whereIn($this->foreignKey, $this->getKeys($models, $this->localKey)); } /** diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 953815e9e..b69bfd46f 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -164,14 +164,15 @@ public static function noConstraints(Closure $callback) /** * Get all of the primary keys for an array of models. * - * @param array $models + * @param array $models + * @param string $key * @return array */ - protected function getKeys(array $models) + protected function getKeys(array $models, $key = null) { - return array_values(array_map(function($value) + return array_values(array_map(function($value) use ($key) { - return $value->getKey(); + return $key ? $value->getAttribute($key) : $value->getKey(); }, $models)); } From c5e655ce266d929d0a3d8ac990e07de28a6a8531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Ma=C5=82ecki?= Date: Fri, 27 Dec 2013 20:55:06 +0100 Subject: [PATCH 019/577] Fix RefreshCommand. --- Console/Migrations/RefreshCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index b1b6a3ae2..2e97098ee 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -37,7 +37,7 @@ public function fire() if ($this->needsSeeding()) { - $this->runSeeder(); + $this->runSeeder($database); } } @@ -52,11 +52,12 @@ protected function needsSeeding() } /** - * Run the databsae seeder command. + * Run the database seeder command. * + * @param string $database * @return void */ - protected function runSeeder() + protected function runSeeder($database) { $class = $this->option('seeder') ?: 'DatabaseSeeder'; From 0961d4ecc1ea310d0d40232bd7bae6338e11fcf8 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Sat, 28 Dec 2013 21:25:47 +0200 Subject: [PATCH 020/577] Abstracting "new Builder" in Model Implements: #3071 --- Eloquent/Model.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index bf0164800..d561abafa 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1598,14 +1598,25 @@ public function freshTimestampString() } /** - * Get a new query builder for the model's table. - * - * @param bool $excludeDeleted - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function newQuery($excludeDeleted = true) - { - $builder = new Builder($this->newBaseQueryBuilder()); + * Get a new base query builder for the model's query builder. + * + * @param \Illuminate\Database\Query\Builder $baseQueryBuilder + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newQueryBuilder($baseQueryBuilder) + { + return new Builder($baseQueryBuilder); + } + + /** + * Get a new query builder for the model's table. + * + * @param bool $excludeDeleted + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newQuery($excludeDeleted = true) + { + $builder = $this->newQueryBuilder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model From 78c036391be1553f0c07711ff64523e8f9955657 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 28 Dec 2013 13:38:15 -0600 Subject: [PATCH 021/577] cleaning up some code. --- Eloquent/Model.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d561abafa..21600663f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1598,25 +1598,14 @@ public function freshTimestampString() } /** - * Get a new base query builder for the model's query builder. - * - * @param \Illuminate\Database\Query\Builder $baseQueryBuilder - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function newQueryBuilder($baseQueryBuilder) - { - return new Builder($baseQueryBuilder); - } - - /** - * Get a new query builder for the model's table. - * - * @param bool $excludeDeleted - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function newQuery($excludeDeleted = true) - { - $builder = $this->newQueryBuilder($this->newBaseQueryBuilder()); + * Get a new query builder for the model's table. + * + * @param bool $excludeDeleted + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newQuery($excludeDeleted = true) + { + $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model @@ -1641,6 +1630,17 @@ public function newQueryWithDeleted() return $this->newQuery(false); } + /** + * Create a new Eloquent query builder for the model. + * + * @param \Illuminate\Database\Query\Builder $query + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newEloquentBuilder($query) + { + return new Builder($query); + } + /** * Determine if the model instance has been soft-deleted. * @@ -2794,7 +2794,7 @@ public function offsetUnset($offset) public function __isset($key) { return ((isset($this->attributes[$key]) || isset($this->relations[$key])) || - ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))); + ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))); } /** From 3af33bfab82d00e58d6ea3e138a52d5797e0a9a5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 28 Dec 2013 14:01:41 -0600 Subject: [PATCH 022/577] Allow whereHas on belongsTo relations. --- Eloquent/Relations/BelongsTo.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsTo.php b/Eloquent/Relations/BelongsTo.php index eef442070..f11cc81ff 100755 --- a/Eloquent/Relations/BelongsTo.php +++ b/Eloquent/Relations/BelongsTo.php @@ -3,6 +3,7 @@ use LogicException; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Expression; use Illuminate\Database\Eloquent\Collection; class BelongsTo extends Relation { @@ -85,7 +86,11 @@ public function addConstraints() */ public function getRelationCountQuery(Builder $query) { - throw new LogicException('Has method invalid on "belongsTo" relations.'); + $query->select(new Expression('count(*)')); + + $otherKey = $this->wrap($query->getModel()->getTable().'.'.$this->otherKey); + + return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); } /** @@ -227,4 +232,14 @@ public function getForeignKey() return $this->foreignKey; } + /** + * Get the fully qualified foreign key of the relationship. + * + * @return string + */ + public function getQualifiedForeignKey() + { + return $this->parent->getTable().'.'.$this->foreignKey; + } + } \ No newline at end of file From 62112f0dac51fdbb53f8318828af7e3ded84478f Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sun, 29 Dec 2013 11:42:03 +1100 Subject: [PATCH 023/577] Allows Seeder execution absent of a Command object --- Seeder.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Seeder.php b/Seeder.php index 5a378856d..d9d868a64 100755 --- a/Seeder.php +++ b/Seeder.php @@ -36,7 +36,10 @@ public function call($class) { $this->resolve($class)->run(); - $this->command->getOutput()->writeln("Seeded: $class"); + if (isset($this->command)) + { + $this->command->getOutput()->writeln("Seeded: $class"); + } } /** @@ -85,4 +88,4 @@ public function setCommand(Command $command) return $this; } -} \ No newline at end of file +} From 82c4456493ed4c07a4611c646ceae3551bead9d8 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sun, 29 Dec 2013 11:49:25 +1100 Subject: [PATCH 024/577] Fix indent --- Seeder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Seeder.php b/Seeder.php index d9d868a64..563426a20 100755 --- a/Seeder.php +++ b/Seeder.php @@ -36,10 +36,10 @@ public function call($class) { $this->resolve($class)->run(); - if (isset($this->command)) - { + if (isset($this->command)) + { $this->command->getOutput()->writeln("Seeded: $class"); - } + } } /** From 4394b20155dcbaa68d3f93ab348f4451257ed02a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 30 Dec 2013 23:01:26 +0000 Subject: [PATCH 025/577] Fix eloquent model relation doc blocks --- Eloquent/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 21600663f..02d03523c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -637,7 +637,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat } /** - * Define an polymorphic, inverse one-to-one or many relationship. + * Define a polymorphic, inverse one-to-one or many relationship. * * @param string $name * @param string $type @@ -779,7 +779,7 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $othe } /** - * Define a many-to-many relationship. + * Define a polymorphic many-to-many relationship. * * @param string $related * @param string $name @@ -816,7 +816,7 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, } /** - * Define a many-to-many relationship. + * Define a polymorphic many-to-many relationship. * * @param string $related * @param string $name From 8d172e00cd1e71af9c4edc350a3372e0f1375e55 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 30 Dec 2013 23:39:51 +0000 Subject: [PATCH 026/577] Fix eloquent model relation param docs --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 02d03523c..ec00ffed3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -580,6 +580,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null) * @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) @@ -786,7 +787,7 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $othe * @param string $table * @param string $foreignKey * @param string $otherKey - * @param bool $inverse + * @param bool $inverse * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function morphToMany($related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) @@ -823,7 +824,6 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, * @param string $table * @param string $foreignKey * @param string $otherKey - * @param string $morphClass * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function morphedByMany($related, $name, $table = null, $foreignKey = null, $otherKey = null) From d9b5502c4b7899f21b46e688d0a61c290451ba69 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 30 Dec 2013 23:55:24 +0000 Subject: [PATCH 027/577] morphedByMany is inverse --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ec00ffed3..fad001197 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -817,7 +817,7 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, } /** - * Define a polymorphic many-to-many relationship. + * Define a polymorphic, inverse many-to-many relationship. * * @param string $related * @param string $name From 536c7e041b120d97cbf6026a894e5c34ee5d527f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 31 Dec 2013 14:24:48 -0600 Subject: [PATCH 028/577] rename some classes for consistency. --- .../Migrations/{MakeCommand.php => MigrateMakeCommand.php} | 4 ++-- MigrationServiceProvider.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename Console/Migrations/{MakeCommand.php => MigrateMakeCommand.php} (98%) mode change 100755 => 100644 diff --git a/Console/Migrations/MakeCommand.php b/Console/Migrations/MigrateMakeCommand.php old mode 100755 new mode 100644 similarity index 98% rename from Console/Migrations/MakeCommand.php rename to Console/Migrations/MigrateMakeCommand.php index 2ca9e7763..a03a1a264 --- a/Console/Migrations/MakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -4,7 +4,7 @@ use Symfony\Component\Console\Input\InputArgument; use Illuminate\Database\Migrations\MigrationCreator; -class MakeCommand extends BaseCommand { +class MigrateMakeCommand extends BaseCommand { /** * The console command name. @@ -64,7 +64,7 @@ public function fire() $table = $this->input->getOption('table'); $create = $this->input->getOption('create'); - + if ( ! $table && is_string($create)) { $table = $create; diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 6915d9375..71b3b58c2 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -3,12 +3,12 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Database\Migrations\Migrator; use Illuminate\Database\Migrations\MigrationCreator; -use Illuminate\Database\Console\Migrations\MakeCommand; use Illuminate\Database\Console\Migrations\ResetCommand; use Illuminate\Database\Console\Migrations\RefreshCommand; use Illuminate\Database\Console\Migrations\InstallCommand; use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\Console\Migrations\RollbackCommand; +use Illuminate\Database\Console\Migrations\MigrateMakeCommand; use Illuminate\Database\Migrations\DatabaseMigrationRepository; class MigrationServiceProvider extends ServiceProvider { @@ -185,7 +185,7 @@ protected function registerMakeCommand() $packagePath = $app['path.base'].'/vendor'; - return new MakeCommand($creator, $packagePath); + return new MigrateMakeCommand($creator, $packagePath); }); } From 1e5552e91cbd728140fca2ca5493ed99d3a617e5 Mon Sep 17 00:00:00 2001 From: Youpie Date: Wed, 1 Jan 2014 23:33:37 +0100 Subject: [PATCH 029/577] Run totallyGuarded() once outside of loop. The boolean returned by totallyGuarded() will never change during the loop. Running the method outside of the foreach avoids one unnecessary count() and two checks for each iteration. --- Eloquent/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index fad001197..ee1a6e25b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -316,6 +316,8 @@ public static function observe($class) */ public function fill(array $attributes) { + $totallyGuarded = $this->totallyGuarded(); + foreach ($this->fillableFromArray($attributes) as $key => $value) { $key = $this->removeTableFromKey($key); @@ -327,7 +329,7 @@ public function fill(array $attributes) { $this->setAttribute($key, $value); } - elseif ($this->totallyGuarded()) + elseif ($totallyGuarded) { throw new MassAssignmentException($key); } From 64e99764130593597581c0c8b9dd07396111477c Mon Sep 17 00:00:00 2001 From: Suhayb El Wardany Date: Sun, 5 Jan 2014 05:54:49 +0200 Subject: [PATCH 030/577] Add database prefix to renameColumn Fixes an issue where renameColumn throws an exception if a database prefix is set. Signed-off-by: Suhayb El Wardany --- Schema/Grammars/Grammar.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index 7d7424674..29c7897bd 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -23,7 +23,9 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne { $schema = $connection->getDoctrineSchemaManager(); - $column = $connection->getDoctrineColumn($blueprint->getTable(), $command->from); + $table = $this->getTablePrefix() . $blueprint->getTable(); + + $column = $connection->getDoctrineColumn($table, $command->from); $tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema); @@ -255,11 +257,13 @@ protected function getDefaultValue($value) */ protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema) { - $tableDiff = new TableDiff($blueprint->getTable()); + $table = $this->getTablePrefix() . $blueprint->getTable(); + + $tableDiff = new TableDiff($table); - $tableDiff->fromTable = $schema->listTableDetails($blueprint->getTable()); + $tableDiff->fromTable = $schema->listTableDetails($table); return $tableDiff; } -} \ No newline at end of file +} From 8a5fb2dc80e23b63fb8708501e0a03c99ab293bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Jan 2014 22:11:22 -0600 Subject: [PATCH 031/577] Fix spacing. --- Schema/Grammars/Grammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index 29c7897bd..c5c57ccef 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -23,7 +23,7 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne { $schema = $connection->getDoctrineSchemaManager(); - $table = $this->getTablePrefix() . $blueprint->getTable(); + $table = $this->getTablePrefix().$blueprint->getTable(); $column = $connection->getDoctrineColumn($table, $command->from); @@ -257,7 +257,7 @@ protected function getDefaultValue($value) */ protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema) { - $table = $this->getTablePrefix() . $blueprint->getTable(); + $table = $this->getTablePrefix().$blueprint->getTable(); $tableDiff = new TableDiff($table); From b8ec34025540bfd391edfcfd09cd965d637a1a46 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Jan 2014 22:27:38 -0600 Subject: [PATCH 032/577] Adding integer serial types. --- Schema/Grammars/MySqlGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 1398682e5..ceb1a22d6 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -25,7 +25,7 @@ class MySqlGrammar extends Grammar { * * @var array */ - protected $serials = array('bigInteger', 'integer'); + protected $serials = array('bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'); /** * Compile the query to determine the list of tables. From c443685f2c08856e1240b536e1837b820ff99138 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 5 Jan 2014 18:14:17 +0000 Subject: [PATCH 033/577] Unused database use statements and @throws --- Eloquent/Model.php | 1 - Eloquent/Relations/BelongsTo.php | 5 +---- Query/Processors/MySqlProcessor.php | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ee1a6e25b..51d9e1111 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1,6 +1,5 @@ parent->getTable().'.'.$this->foreignKey; } -} \ No newline at end of file +} diff --git a/Query/Processors/MySqlProcessor.php b/Query/Processors/MySqlProcessor.php index 990810866..dd2f4d892 100644 --- a/Query/Processors/MySqlProcessor.php +++ b/Query/Processors/MySqlProcessor.php @@ -1,7 +1,5 @@ Date: Tue, 7 Jan 2014 21:23:29 -0600 Subject: [PATCH 034/577] work on self joining has clause on belongsToMany relationships. --- Eloquent/Builder.php | 2 +- Eloquent/Relations/BelongsTo.php | 3 +- Eloquent/Relations/BelongsToMany.php | 42 +++++++++++++++++++++++++-- Eloquent/Relations/HasManyThrough.php | 5 ++-- Eloquent/Relations/MorphOneOrMany.php | 5 ++-- Eloquent/Relations/Relation.php | 3 +- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b4ff6415a..b3a8df166 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -594,7 +594,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ { $relation = $this->getHasRelationQuery($relation); - $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery()); + $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this); if ($callback) call_user_func($callback, $query); diff --git a/Eloquent/Relations/BelongsTo.php b/Eloquent/Relations/BelongsTo.php index 675f8036f..e222dad53 100755 --- a/Eloquent/Relations/BelongsTo.php +++ b/Eloquent/Relations/BelongsTo.php @@ -79,9 +79,10 @@ public function addConstraints() * Add the constraints for a relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationCountQuery(Builder $query) + public function getRelationCountQuery(Builder $query, Builder $parent) { $query->select(new Expression('count(*)')); diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index a4534379c..98c1aff04 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -239,13 +239,49 @@ public function addConstraints() * Add the constraints for a relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationCountQuery(Builder $query) + public function getRelationCountQuery(Builder $query, Builder $parent) { - $this->setJoin($query); + if ($original->getQuery()->from == $query->getQuery()->from) + { + return $this->getRelationCountQueryForSelfJoin($query, $parent); + } + else + { + $this->setJoin($query); + + return parent::getRelationCountQuery($query, $parent); + } + } - return parent::getRelationCountQuery($query); + /** + * Add the constraints for a relationship count query on the same table. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent) + { + $query->select(new \Illuminate\Database\Query\Expression('count(*)')); + + $query->from($this->table.' as '.$hash = $this->getRelationCountHash()); + + $key = $this->wrap($this->getQualifiedParentKeyName()); + + return $query->where($hash.'.person_id', '=', new \Illuminate\Database\Query\Expression($key)); + } + + /** + * Get a relationship join table hash. + * + * @return string + */ + public function getRelationCountHash() + { + return 'self_'.md5(microtime(true)); } /** diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 3f6bfed55..cb07d3415 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -50,13 +50,14 @@ public function addConstraints() * Add the constraints for a relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationCountQuery(Builder $query) + public function getRelationCountQuery(Builder $query, Builder $parent) { $this->setJoin($query); - return parent::getRelationCountQuery($query); + return parent::getRelationCountQuery($query, $parent); } /** diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index cf18da984..2dff40518 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -57,11 +57,12 @@ public function addConstraints() * Add the constraints for a relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationCountQuery(Builder $query) + public function getRelationCountQuery(Builder $query, Builder $parent) { - $query = parent::getRelationCountQuery($query); + $query = parent::getRelationCountQuery($query, $parent); return $query->where($this->morphType, $this->morphClass); } diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index b69bfd46f..403075ae4 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -130,9 +130,10 @@ public function rawUpdate(array $attributes = array()) * Add the constraints for a relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent * @return \Illuminate\Database\Eloquent\Builder */ - public function getRelationCountQuery(Builder $query) + public function getRelationCountQuery(Builder $query, Builder $parent) { $query->select(new Expression('count(*)')); From 7741475e66c6deb5e7f754f62b02de9ef2b4f72c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 7 Jan 2014 21:48:28 -0600 Subject: [PATCH 035/577] Fix variable name. --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 98c1aff04..cabfaf3ed 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -244,7 +244,7 @@ public function addConstraints() */ public function getRelationCountQuery(Builder $query, Builder $parent) { - if ($original->getQuery()->from == $query->getQuery()->from) + if ($parent->getQuery()->from == $query->getQuery()->from) { return $this->getRelationCountQueryForSelfJoin($query, $parent); } From 739aa685881ceadff15047779bd40a58208eddf3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 7 Jan 2014 22:12:58 -0600 Subject: [PATCH 036/577] Make morph integer unsigned. --- Schema/Blueprint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index ba0225ffe..26523254f 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -654,7 +654,7 @@ public function binary($column) */ public function morphs($name) { - $this->integer("{$name}_id"); + $this->unsignedInteger("{$name}_id"); $this->string("{$name}_type"); } From f038f8237735ca8d8360d2936edddd777464ac0d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Jan 2014 14:58:20 -0600 Subject: [PATCH 037/577] working on variable. --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index cabfaf3ed..54ac60a01 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -271,7 +271,7 @@ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent $key = $this->wrap($this->getQualifiedParentKeyName()); - return $query->where($hash.'.person_id', '=', new \Illuminate\Database\Query\Expression($key)); + return $query->where($hash.'.'.$this->foreignKey, '=', new \Illuminate\Database\Query\Expression($key)); } /** From 307e89579f36023045af8addadbc4a5384615e86 Mon Sep 17 00:00:00 2001 From: s1owjke Date: Sun, 12 Jan 2014 13:55:57 +0300 Subject: [PATCH 038/577] Fix doc blocks. --- Connection.php | 2 +- Connectors/ConnectorInterface.php | 2 +- Connectors/MySqlConnector.php | 2 +- Connectors/SQLiteConnector.php | 2 +- Console/Migrations/InstallCommand.php | 4 ++-- Eloquent/Model.php | 2 +- Eloquent/Relations/BelongsToMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/MorphToMany.php | 2 +- Query/Builder.php | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Connection.php b/Connection.php index b5ff3fadd..50399b8cd 100755 --- a/Connection.php +++ b/Connection.php @@ -60,7 +60,7 @@ class Connection implements ConnectionInterface { /** * The cache manager instance. * - * @var \Illuminate\Cache\CacheManger + * @var \Illuminate\Cache\CacheManager */ protected $cache; diff --git a/Connectors/ConnectorInterface.php b/Connectors/ConnectorInterface.php index c734f9dbe..a3f5ea571 100755 --- a/Connectors/ConnectorInterface.php +++ b/Connectors/ConnectorInterface.php @@ -6,7 +6,7 @@ interface ConnectorInterface { * Establish a database connection. * * @param array $config - * @return PDO + * @return \PDO */ public function connect(array $config); diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index fbdadfb0d..dc1b57163 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -6,7 +6,7 @@ class MySqlConnector extends Connector implements ConnectorInterface { * Establish a database connection. * * @param array $config - * @return PDO + * @return \PDO */ public function connect(array $config) { diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index 5d9f75dc0..65c7d2beb 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -6,7 +6,7 @@ class SQLiteConnector extends Connector implements ConnectorInterface { * Establish a database connection. * * @param array $config - * @return PDO + * @return \PDO * * @throws \InvalidArgumentException */ diff --git a/Console/Migrations/InstallCommand.php b/Console/Migrations/InstallCommand.php index 9feb2aed1..09b63f439 100755 --- a/Console/Migrations/InstallCommand.php +++ b/Console/Migrations/InstallCommand.php @@ -23,14 +23,14 @@ class InstallCommand extends Command { /** * The repository instance. * - * @var \Illuminate\Database\Console\Migrations\MigrationRepositoryInterface + * @var \Illuminate\Database\Migrations\MigrationRepositoryInterface */ protected $repository; /** * Create a new migration install command instance. * - * @param \Illuminate\Database\Console\Migrations\MigrationRepositoryInterface $repository + * @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository * @return void */ public function __construct(MigrationRepositoryInterface $repository) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 51d9e1111..69e9aacc9 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1708,7 +1708,7 @@ public function newCollection(array $models = array()) * @param array $attributes * @param string $table * @param bool $exists - * @return \Illuminate\Database\Eloquent\Relation\Pivot + * @return \Illuminate\Database\Eloquent\Relations\Pivot */ public function newPivot(Model $parent, array $attributes, $table, $exists) { diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 54ac60a01..85148b2b1 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -888,7 +888,7 @@ public function newPivotStatementForId($id) * * @param array $attributes * @param bool $exists - * @return \Illuminate\Database\Eloquent\Relation\Pivot + * @return \Illuminate\Database\Eloquent\Relations\Pivot */ public function newPivot(array $attributes = array(), $exists = false) { diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index cb07d3415..056484d54 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -63,7 +63,7 @@ public function getRelationCountQuery(Builder $query, Builder $parent) /** * Set the join clause on the query. * - * @param \Illuminate\Databaes\Eloquent\Builder|null $query + * @param \Illuminate\Database\Eloquent\Builder|null $query * @return void */ protected function setJoin(Builder $query = null) diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 26b5dc852..3744fd7c6 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -108,7 +108,7 @@ protected function newPivotQuery() * * @param array $attributes * @param bool $exists - * @return \Illuminate\Database\Eloquent\Relation\Pivot + * @return \Illuminate\Database\Eloquent\Relations\Pivot */ public function newPivot(array $attributes = array(), $exists = false) { diff --git a/Query/Builder.php b/Query/Builder.php index 915d0c10b..a148d427e 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -403,7 +403,7 @@ public function orWhere($column, $operator = null, $value = null) * Determine if the given operator and value combination is legal. * * @param string $operator - * @param mxied $value + * @param mixed $value * @return bool */ protected function invalidOperatorAndValue($operator, $value) From 3abca3f2db91099cc96bd466f715e173a43d7ea8 Mon Sep 17 00:00:00 2001 From: Ivan Orbovic Date: Sun, 12 Jan 2014 17:30:23 +0100 Subject: [PATCH 039/577] getCached comment typo fix --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 915d0c10b..db0390bc3 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1214,7 +1214,7 @@ public function getCached($columns = array('*')) { if (is_null($this->columns)) $this->columns = $columns; - // If the query is requested ot be cached, we will cache it using a unique key + // If the query is requested to be cached, we will cache it using a unique key // for this database connection and query statement, including the bindings // that are used on this query, providing great convenience when caching. list($key, $minutes) = $this->getCacheInfo(); From 45b83675624deb170da29e44db7c5a730272aba0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 Jan 2014 10:39:52 -0600 Subject: [PATCH 040/577] Rename View and Pagination Environments to Factory. --- Connection.php | 12 ++++++------ Eloquent/Builder.php | 4 ++-- Query/Builder.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Connection.php b/Connection.php index 50399b8cd..f0ea235de 100755 --- a/Connection.php +++ b/Connection.php @@ -51,9 +51,9 @@ class Connection implements ConnectionInterface { protected $events; /** - * The paginator environment instance. + * The paginator factory instance. * - * @var \Illuminate\Pagination\Paginator + * @var \Illuminate\Pagination\Factory */ protected $paginator; @@ -794,9 +794,9 @@ public function setEventDispatcher(\Illuminate\Events\Dispatcher $events) } /** - * Get the paginator environment instance. + * Get the paginator factory instance. * - * @return \Illuminate\Pagination\Environment + * @return \Illuminate\Pagination\Factory */ public function getPaginator() { @@ -809,9 +809,9 @@ public function getPaginator() } /** - * Set the pagination environment instance. + * Set the pagination factory instance. * - * @param \Illuminate\Pagination\Environment|\Closure $paginator + * @param \Illuminate\Pagination\Factory|\Closure $paginator * @return void */ public function setPaginator($paginator) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b3a8df166..38b6bc143 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -235,7 +235,7 @@ public function paginate($perPage = null, $columns = array('*')) /** * Get a paginator for a grouped statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -250,7 +250,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Get a paginator for an ungrouped statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator diff --git a/Query/Builder.php b/Query/Builder.php index a42b99fe8..7ab59faa2 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1408,7 +1408,7 @@ public function paginate($perPage = 15, $columns = array('*')) /** * Create a paginator for a grouped pagination statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -1423,7 +1423,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Build a paginator instance from a raw result array. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param array $results * @param int $perPage * @return \Illuminate\Pagination\Paginator @@ -1443,7 +1443,7 @@ public function buildRawPaginator($paginator, $results, $perPage) /** * Create a paginator for an un-grouped pagination statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator From e02c527633d72a422293de502e655ed56bdcb1c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 Jan 2014 13:39:13 -0600 Subject: [PATCH 041/577] Revert "Rename View and Pagination Environments to Factory." This reverts commit 8b39745bfb67e306a3e1a8b9536711fe4700c8f7. --- Connection.php | 12 ++++++------ Eloquent/Builder.php | 4 ++-- Query/Builder.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Connection.php b/Connection.php index f0ea235de..50399b8cd 100755 --- a/Connection.php +++ b/Connection.php @@ -51,9 +51,9 @@ class Connection implements ConnectionInterface { protected $events; /** - * The paginator factory instance. + * The paginator environment instance. * - * @var \Illuminate\Pagination\Factory + * @var \Illuminate\Pagination\Paginator */ protected $paginator; @@ -794,9 +794,9 @@ public function setEventDispatcher(\Illuminate\Events\Dispatcher $events) } /** - * Get the paginator factory instance. + * Get the paginator environment instance. * - * @return \Illuminate\Pagination\Factory + * @return \Illuminate\Pagination\Environment */ public function getPaginator() { @@ -809,9 +809,9 @@ public function getPaginator() } /** - * Set the pagination factory instance. + * Set the pagination environment instance. * - * @param \Illuminate\Pagination\Factory|\Closure $paginator + * @param \Illuminate\Pagination\Environment|\Closure $paginator * @return void */ public function setPaginator($paginator) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 38b6bc143..b3a8df166 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -235,7 +235,7 @@ public function paginate($perPage = null, $columns = array('*')) /** * Get a paginator for a grouped statement. * - * @param \Illuminate\Pagination\Factory $paginator + * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -250,7 +250,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Get a paginator for an ungrouped statement. * - * @param \Illuminate\Pagination\Factory $paginator + * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator diff --git a/Query/Builder.php b/Query/Builder.php index 7ab59faa2..a42b99fe8 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1408,7 +1408,7 @@ public function paginate($perPage = 15, $columns = array('*')) /** * Create a paginator for a grouped pagination statement. * - * @param \Illuminate\Pagination\Factory $paginator + * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -1423,7 +1423,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Build a paginator instance from a raw result array. * - * @param \Illuminate\Pagination\Factory $paginator + * @param \Illuminate\Pagination\Environment $paginator * @param array $results * @param int $perPage * @return \Illuminate\Pagination\Paginator @@ -1443,7 +1443,7 @@ public function buildRawPaginator($paginator, $results, $perPage) /** * Create a paginator for an un-grouped pagination statement. * - * @param \Illuminate\Pagination\Factory $paginator + * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator From cec2c59d40605f120568d2601344333f03072cfd Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Mon, 13 Jan 2014 22:23:28 +0100 Subject: [PATCH 042/577] Check IoC for custom Connector instances --- Connectors/ConnectionFactory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index 5a27557c4..8269625a5 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -171,6 +171,11 @@ public function createConnector(array $config) throw new \InvalidArgumentException("A driver must be specified."); } + if ($this->container->bound($key = "db.connector.{$config['driver']}")) + { + return $this->container->make($key); + } + switch ($config['driver']) { case 'mysql': From f8c2b9898f18dfb1b994748567db4a46138d7a0e Mon Sep 17 00:00:00 2001 From: Tim Roberson Date: Mon, 13 Jan 2014 17:14:26 -0500 Subject: [PATCH 043/577] Pass config name to database extensions. --- DatabaseManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 82e6da7aa..2d9ee17e3 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -111,7 +111,7 @@ protected function makeConnection($name) // Closure and pass it the config allowing it to resolve the connection. if (isset($this->extensions[$name])) { - return call_user_func($this->extensions[$name], $config); + return call_user_func($this->extensions[$name], $config, $name); } $driver = $config['driver']; @@ -121,7 +121,7 @@ protected function makeConnection($name) // resolver for the drivers themselves which applies to all connections. if (isset($this->extensions[$driver])) { - return call_user_func($this->extensions[$driver], $config); + return call_user_func($this->extensions[$driver], $config, $name); } return $this->factory->make($config, $name); From 0c5f108a5b2b673f31ce84663a7f281f46b62609 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 Jan 2014 17:13:05 -0600 Subject: [PATCH 044/577] Rename view and pagination environments to "factory". --- Connection.php | 4 ++-- Eloquent/Builder.php | 4 ++-- Query/Builder.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Connection.php b/Connection.php index 50399b8cd..71b8faf17 100755 --- a/Connection.php +++ b/Connection.php @@ -796,7 +796,7 @@ public function setEventDispatcher(\Illuminate\Events\Dispatcher $events) /** * Get the paginator environment instance. * - * @return \Illuminate\Pagination\Environment + * @return \Illuminate\Pagination\Factory */ public function getPaginator() { @@ -811,7 +811,7 @@ public function getPaginator() /** * Set the pagination environment instance. * - * @param \Illuminate\Pagination\Environment|\Closure $paginator + * @param \Illuminate\Pagination\Factory|\Closure $paginator * @return void */ public function setPaginator($paginator) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b3a8df166..38b6bc143 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -235,7 +235,7 @@ public function paginate($perPage = null, $columns = array('*')) /** * Get a paginator for a grouped statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -250,7 +250,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Get a paginator for an ungrouped statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator diff --git a/Query/Builder.php b/Query/Builder.php index a42b99fe8..7ab59faa2 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1408,7 +1408,7 @@ public function paginate($perPage = 15, $columns = array('*')) /** * Create a paginator for a grouped pagination statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator @@ -1423,7 +1423,7 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Build a paginator instance from a raw result array. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param array $results * @param int $perPage * @return \Illuminate\Pagination\Paginator @@ -1443,7 +1443,7 @@ public function buildRawPaginator($paginator, $results, $perPage) /** * Create a paginator for an un-grouped pagination statement. * - * @param \Illuminate\Pagination\Environment $paginator + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator From 8995e80a58b57a3d9f5b12ad8a30b44163dc7bad Mon Sep 17 00:00:00 2001 From: crynobone Date: Tue, 14 Jan 2014 09:36:14 +0800 Subject: [PATCH 045/577] Bump all components to min PHP 5.4 Signed-off-by: crynobone --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f56a54bec..fa5e7478c 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "illuminate/container": "4.2.*", "illuminate/events": "4.2.*", "illuminate/support": "4.2.*", From 8b58334b427cfc0bdcf04461d0bc1c14f046de01 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Tue, 14 Jan 2014 13:58:52 +0100 Subject: [PATCH 046/577] use JsonSerializable --- Eloquent/Model.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 69e9aacc9..c3bbf3961 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -4,6 +4,7 @@ use ArrayAccess; use Carbon\Carbon; use LogicException; +use JsonSerializable; use Illuminate\Events\Dispatcher; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -20,7 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface { +abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, JsonSerializable { /** * The connection name for the model. @@ -2064,6 +2065,16 @@ public function toJson($options = 0) return json_encode($this->toArray(), $options); } + /** + * Specify data which should be serialized to JSON when encoded with json_encode. + * + * @return array + */ + public function jsonSerialize() + { + return $this->toArray(); + } + /** * Convert the model instance to an array. * From c73bd2aca9e731fde406f9d1790cc2fb77c7db0e Mon Sep 17 00:00:00 2001 From: Youpie Date: Wed, 15 Jan 2014 15:33:42 +0100 Subject: [PATCH 047/577] Fix ignored docblocks --- Eloquent/Collection.php | 2 +- Query/Builder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 7c83ebb0e..753245af8 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -194,7 +194,7 @@ public function unique() return new static(array_values($dictionary)); } - /* + /** * Get a dictionary keyed by primary keys. * * @param \Illuminate\Support\Collection $collection diff --git a/Query/Builder.php b/Query/Builder.php index a42b99fe8..0f9fd9833 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -928,7 +928,7 @@ public function oldest($column = 'created_at') return $this->orderBy($column, 'asc'); } - /* + /** * Add a raw "order by" clause to the query. * * @param string $sql From 716c6f7262282f7028080b6c4fe4e956735986e4 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Wed, 15 Jan 2014 15:37:57 +0100 Subject: [PATCH 048/577] add methods --- Eloquent/Relations/BelongsTo.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Eloquent/Relations/BelongsTo.php b/Eloquent/Relations/BelongsTo.php index e222dad53..f1179a99c 100755 --- a/Eloquent/Relations/BelongsTo.php +++ b/Eloquent/Relations/BelongsTo.php @@ -240,4 +240,24 @@ public function getQualifiedForeignKey() return $this->parent->getTable().'.'.$this->foreignKey; } + /** + * Get the associated key of the relationship. + * + * @return string + */ + public function getOtherKey() + { + return $this->otherKey; + } + + /** + * Get the fully qualified associated key of the relationship. + * + * @return string + */ + public function getQualifiedOtherKeyName() + { + return $this->related->getTable().'.'.$this->otherKey; + } + } From a7d0bba5e6c043ec7e2b686d7466c5754a957e8d Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 16 Jan 2014 17:13:31 +0100 Subject: [PATCH 049/577] Pass getBindings through to querybuilder --- Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b3a8df166..5d9cca0ab 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -34,8 +34,8 @@ class Builder { * @var array */ protected $passthru = array( - 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', - 'count', 'min', 'max', 'avg', 'sum', 'exists', + 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'count', + 'min', 'max', 'avg', 'sum', 'exists', 'getBindings', ); /** From 2644140ea9f5250c9599dd25b457a23fcd7eed6b Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 16 Jan 2014 17:53:49 +0100 Subject: [PATCH 050/577] changes and tests --- Eloquent/Builder.php | 40 ++++++++++++++++++++++++++++++++++++++++ Query/Builder.php | 19 ++++++++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b3a8df166..2b2229fce 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -580,6 +580,46 @@ protected function isNested($name, $relation) return $dots && starts_with($name, $relation) && $name != $relation; } + /** + * Add a basic where clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @param string $boolean + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function where($column, $operator = null, $value = null, $boolean = 'and') + { + if ($column instanceof Closure) + { + $query = $this->model->newQuery(); + + call_user_func($column, $query); + + $this->query->addNestedWhereQuery($query->getQuery(), $boolean); + } + else + { + $this->query->where($column, $operator, $value, $boolean); + } + + return $this; + } + + /** + * Add an "or where" clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function orWhere($column, $operator = null, $value = null) + { + return $this->where($column, $operator, $value, 'or'); + } + /** * Add a relationship count condition to the query. * diff --git a/Query/Builder.php b/Query/Builder.php index 0f9fd9833..09e1aea1b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -514,19 +514,28 @@ public function whereNested(Closure $callback, $boolean = 'and') // To handle nested queries we'll actually create a brand new query instance // and pass it off to the Closure that we have. The Closure can simply do // do whatever it wants to a query then we will store it for compiling. - $type = 'Nested'; - $query = $this->newQuery(); $query->from($this->from); call_user_func($callback, $query); - // Once we have let the Closure do its things, we can gather the bindings on - // the nested query builder and merge them into these bindings since they - // need to get extracted out of the children and assigned to the array. + return $this->addNestedWhereQuery($query, $boolean); + } + + /** + * Add another query builder as a nested where to the query builder. + * + * @param \Illuminate\Database\Query\Builder|static $query + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function addNestedWhereQuery($query, $boolean = 'and') + { if (count($query->wheres)) { + $type = 'Nested'; + $this->wheres[] = compact('type', 'query', 'boolean'); $this->mergeBindings($query); From 80672668ad4122e56bd26db0e9c7109b8a7daf77 Mon Sep 17 00:00:00 2001 From: Sasan Hezarkhani Date: Thu, 16 Jan 2014 11:09:09 -0800 Subject: [PATCH 051/577] Database connection to return the read PDO connection if in transaction --- Connection.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Connection.php b/Connection.php index 50399b8cd..9064e6969 100755 --- a/Connection.php +++ b/Connection.php @@ -649,6 +649,11 @@ public function getPdo() */ public function getReadPdo() { + if ($this->transactions >= 1) + { + return $this->getPdo(); + } + return $this->readPdo ?: $this->pdo; } From 91d67d57f172022cfb6682d210ba73da247fcce0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 16 Jan 2014 21:16:59 -0600 Subject: [PATCH 052/577] Fix lines. --- Connection.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Connection.php b/Connection.php index 9064e6969..6b7cfcc16 100755 --- a/Connection.php +++ b/Connection.php @@ -649,10 +649,7 @@ public function getPdo() */ public function getReadPdo() { - if ($this->transactions >= 1) - { - return $this->getPdo(); - } + if ($this->transactions >= 1) return $this->getPdo(); return $this->readPdo ?: $this->pdo; } From 8ecc0034a13034e7387062e800afcd7f046b76ea Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 17 Jan 2014 14:11:45 -0600 Subject: [PATCH 053/577] Unify composer wildcard reference. --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 4f05bc08c..19bbdbc49 100755 --- a/composer.json +++ b/composer.json @@ -10,17 +10,17 @@ ], "require": { "php": ">=5.3.0", - "illuminate/container": "4.1.x", - "illuminate/events": "4.1.x", - "illuminate/support": "4.1.x", + "illuminate/container": "4.1.*", + "illuminate/events": "4.1.*", + "illuminate/support": "4.1.*", "nesbot/carbon": "1.*" }, "require-dev": { - "illuminate/cache": "4.1.x", - "illuminate/console": "4.1.x", - "illuminate/filesystem": "4.1.x", - "illuminate/pagination": "4.1.x", - "illuminate/support": "4.1.x", + "illuminate/cache": "4.1.*", + "illuminate/console": "4.1.*", + "illuminate/filesystem": "4.1.*", + "illuminate/pagination": "4.1.*", + "illuminate/support": "4.1.*", "mockery/mockery": "0.7.2", "phpunit/phpunit": "3.7.*" }, From a9741dcad7a397e56e21a3a9afb79d9bbed892de Mon Sep 17 00:00:00 2001 From: Stidges Date: Fri, 17 Jan 2014 23:38:07 +0100 Subject: [PATCH 054/577] Add 'except' and 'only' methods to Eloquent Collection class. --- Eloquent/Collection.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 753245af8..0cd8987cc 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -194,6 +194,32 @@ public function unique() return new static(array_values($dictionary)); } + /** + * Returns all models in the collection except the models with specified keys. + * + * @param mixed $keys + * @return \Illuminate\Support\Collection + */ + public function except($keys) + { + $dictionary = array_except($this->getDictionary($this), $keys); + + return new static(array_values($dictionary)); + } + + /** + * Returns only the models from the collection with the specified keys. + * + * @param mixed $keys + * @return \Illuminate\Support\Collection + */ + public function only($keys) + { + $dictionary = array_only($this->getDictionary($this), $keys); + + return new static(array_values($dictionary)); + } + /** * Get a dictionary keyed by primary keys. * From c5789953e9991e49159f1731a9fb6ed3c9560117 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Wed, 22 Jan 2014 08:26:09 +0100 Subject: [PATCH 055/577] strtolower -> camel_case --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 85148b2b1..953951d54 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -843,7 +843,7 @@ protected function touchingParent() */ protected function guessInverseRelation() { - return strtolower(str_plural(class_basename($this->getParent()))); + return camel_case(str_plural(class_basename($this->getParent()))); } /** From ee309d34d933b1110e359320cfecfb25780e7762 Mon Sep 17 00:00:00 2001 From: hassansin Date: Wed, 22 Jan 2014 16:34:12 +0600 Subject: [PATCH 056/577] added orHaving(), works similar to orHavingRaw() --- Query/Builder.php | 17 +++++++++++++++-- Query/Grammars/Grammar.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index df7cf1fff..1fa12ca87 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -848,17 +848,30 @@ public function groupBy() * @param string $value * @return \Illuminate\Database\Query\Builder|static */ - public function having($column, $operator = null, $value = null) + public function having($column, $operator = null, $value = null,$boolean = 'and') { $type = 'basic'; - $this->havings[] = compact('type', 'column', 'operator', 'value'); + $this->havings[] = compact('type', 'column', 'operator', 'value','boolean'); $this->bindings[] = $value; return $this; } + /** + * Add an "or having" clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orHaving($column, $operator = null, $value = null) + { + return $this->having($column, $operator, $value, 'or'); + } + /** * Add a raw having clause to the query. * diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index e5e2cb688..689eae859 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -448,7 +448,7 @@ protected function compileBasicHaving($having) $parameter = $this->parameter($having['value']); - return 'and '.$column.' '.$having['operator'].' '.$parameter; + return $having['boolean'].' '.$column.' '.$having['operator'].' '.$parameter; } /** From 08dadcecbda739d6383a6c20904e2d6857932ada Mon Sep 17 00:00:00 2001 From: Dan Harper Date: Thu, 23 Jan 2014 18:41:32 +0000 Subject: [PATCH 057/577] Ensure date attributes on an Eloquent model are output in same format when the model is converted to an array as if you were to directly access the property on the model. --- Eloquent/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 69e9aacc9..97114fd66 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2085,6 +2085,16 @@ public function attributesToArray() { $attributes = $this->getArrayableAttributes(); + // Convert all attributes listed as dates to DateTime instances, then back + // to a string. This allows us to output date attributes in the same format + // as if we were to access them directly on the object. + foreach ($this->getDates() as $key) + { + if ( ! array_key_exists($key, $attributes)) continue; + + $attributes[$key] = (string) $this->asDateTime($attributes[$key]); + } + // We want to spin through all the mutated attributes for this model and call // the mutator for the attribute. We cache off every mutated attributes so // we don't have to constantly check on attributes that actually change. From 51c5c198f90b588b230f14004b9a89dcdd19b95b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 14 Jan 2014 19:24:11 +0000 Subject: [PATCH 058/577] Micro-optimizations --- Eloquent/Model.php | 4 +--- Migrations/DatabaseMigrationRepository.php | 4 ++-- Query/Grammars/Grammar.php | 4 +--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 69e9aacc9..06cdb4d62 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -316,7 +316,7 @@ public static function observe($class) public function fill(array $attributes) { $totallyGuarded = $this->totallyGuarded(); - + foreach ($this->fillableFromArray($attributes) as $key => $value) { $key = $this->removeTableFromKey($key); @@ -751,8 +751,6 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $othe if (is_null($relation)) { $caller = $this->getBelongsToManyCaller(); - - $name = $caller['function']; } // First, we'll need to determine the foreign key and "other key" for the diff --git a/Migrations/DatabaseMigrationRepository.php b/Migrations/DatabaseMigrationRepository.php index d7104b791..88947100d 100755 --- a/Migrations/DatabaseMigrationRepository.php +++ b/Migrations/DatabaseMigrationRepository.php @@ -82,7 +82,7 @@ public function log($file, $batch) */ public function delete($migration) { - $query = $this->table()->where('migration', $migration->migration)->delete(); + $this->table()->where('migration', $migration->migration)->delete(); } /** @@ -178,4 +178,4 @@ public function setSource($name) $this->connection = $name; } -} \ No newline at end of file +} diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index e5e2cb688..4faf1d6a3 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -410,8 +410,6 @@ protected function compileGroups(Builder $query, $groups) */ protected function compileHavings(Builder $query, $havings) { - $me = $this; - $sql = implode(' ', array_map(array($this, 'compileHaving'), $havings)); return 'having '.preg_replace('/and /', '', $sql, 1); @@ -679,4 +677,4 @@ protected function removeLeadingBoolean($value) return preg_replace('/and |or /', '', $value, 1); } -} \ No newline at end of file +} From c07cb1c7b26b4194e038a62c3a95366d98dd3890 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jan 2014 14:43:10 -0600 Subject: [PATCH 059/577] Added blueprintResolver method. --- Schema/Builder.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Schema/Builder.php b/Schema/Builder.php index 5afc5d352..0793be5b4 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -19,6 +19,13 @@ class Builder { */ protected $grammar; + /** + * The Blueprint resolver callback. + * + * @var \Closure + */ + protected $resolver; + /** * Create a new database Schema manager. * @@ -171,7 +178,14 @@ protected function build(Blueprint $blueprint) */ protected function createBlueprint($table, Closure $callback = null) { - return new Blueprint($table, $callback); + if (isset($this->resolver)) + { + return call_user_func($this->resolver, $table, $callback); + } + else + { + return new Blueprint($table, $callback); + } } /** @@ -197,4 +211,15 @@ public function setConnection(Connection $connection) return $this; } + /** + * Set the Schema Blueprint resolver callback. + * + * @param \Closure $resolver + * @return void + */ + public function blueprintResolver(Closure $resolver) + { + $this->resolver = $resolver; + } + } \ No newline at end of file From e7fe965a4852aeef4efb6a5d2a35a3cd25f75fd7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jan 2014 14:57:07 -0600 Subject: [PATCH 060/577] Fix comments. --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c3bbf3961..ca1b1b0e1 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -317,7 +317,7 @@ public static function observe($class) public function fill(array $attributes) { $totallyGuarded = $this->totallyGuarded(); - + foreach ($this->fillableFromArray($attributes) as $key => $value) { $key = $this->removeTableFromKey($key); @@ -2066,7 +2066,7 @@ public function toJson($options = 0) } /** - * Specify data which should be serialized to JSON when encoded with json_encode. + * Convert the object into something JSON serializable. * * @return array */ From f0e97f431a40cf21f119ca234f4a85515470f629 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jan 2014 16:53:44 -0600 Subject: [PATCH 061/577] Return empty collection if array is empty. --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 06cdb4d62..2efac23ca 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -502,6 +502,8 @@ public static function all($columns = array('*')) */ public static function find($id, $columns = array('*')) { + if (is_array($id) && empty($id)) return new Collection; + $instance = new static; return $instance->newQuery()->find($id, $columns); From c2a91a872bf88bdea29ab60f822b9ae5fc54565f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 29 Jan 2014 08:39:25 -0600 Subject: [PATCH 062/577] Adding toBase method to Eloquent collection. --- Eloquent/Collection.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 753245af8..6f8d591a3 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -212,4 +212,14 @@ protected function getDictionary($collection) return $dictionary; } + /** + * Get a base Support collection instance from this collection. + * + * @return \Illuminate\Support\Collection + */ + public function toBase() + { + return new BaseCollection($this->items); + } + } From 3df285b438655a94efdc80645a1405a81bac1cfb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 29 Jan 2014 09:10:57 -0600 Subject: [PATCH 063/577] Added getDatabaseManager method to capsule. --- Capsule/Manager.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 1b01b0177..f59651463 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -18,6 +18,13 @@ class Manager { */ protected static $instance; + /** + * The database manager instance. + * + * @var \Illuminate\Database\DatabaseManager + */ + protected $manager; + /** * Create a new database capsule manager. * @@ -175,6 +182,16 @@ public function setAsGlobal() static::$instance = $this; } + /** + * Get the database manager instance. + * + * @return \Illuminate\Database\Manager + */ + public function getDatabaseManager() + { + return $this->manager; + } + /** * Get the current event dispatcher instance. * From d2ec783c036a368758b89a744604fb139a3b51a0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 29 Jan 2014 14:49:25 -0600 Subject: [PATCH 064/577] Work on migration publisher. --- Console/Migrations/MigrateMakeCommand.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Console/Migrations/MigrateMakeCommand.php b/Console/Migrations/MigrateMakeCommand.php index a03a1a264..5fc6933eb 100644 --- a/Console/Migrations/MigrateMakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -65,11 +65,7 @@ public function fire() $create = $this->input->getOption('create'); - if ( ! $table && is_string($create)) - { - $table = $create; - } - + if ( ! $table && is_string($create)) $table = $create; // Now we are ready to write the migration out to disk. Once we've written // the migration out, we will dump-autoload for the entire framework to From b357d1533125e36d7d90fbb2cb7c35337b9641cc Mon Sep 17 00:00:00 2001 From: crynobone Date: Wed, 27 Nov 2013 20:52:24 +0800 Subject: [PATCH 065/577] ModelNotFoundException to include setter and getter for model name. This would allow identifying the model name much easier without having to have additional string parser, and at the same time preserve the current message. Signed-off-by: crynobone --- Eloquent/Builder.php | 4 ++-- Eloquent/Model.php | 2 +- Eloquent/ModelNotFoundException.php | 34 ++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index c6c58562e..224ea2b8e 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -95,7 +95,7 @@ public function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = $this->find($id, $columns))) return $model; - throw new ModelNotFoundException; + throw with(new ModelNotFoundException)->setModel(get_class($this->model)); } /** @@ -121,7 +121,7 @@ public function firstOrFail($columns = array('*')) { if ( ! is_null($model = $this->first($columns))) return $model; - throw new ModelNotFoundException; + throw with(new ModelNotFoundException)->setModel(get_class($this->model)); } /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2efac23ca..c0b1869b3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -522,7 +522,7 @@ public static function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = static::find($id, $columns))) return $model; - throw new ModelNotFoundException(get_called_class().' model not found'); + throw with(new ModelNotFoundException)->setModel(get_called_class()); } /** diff --git a/Eloquent/ModelNotFoundException.php b/Eloquent/ModelNotFoundException.php index 25750dc62..c03b232c0 100755 --- a/Eloquent/ModelNotFoundException.php +++ b/Eloquent/ModelNotFoundException.php @@ -1,3 +1,35 @@ model = $model; + $this->message = "{$model} not found"; + + return $this; + } + + /** + * Get the affected eloquent model. + * + * @return string + */ + public function getModel() + { + return $this->model; + } + +} From 6bb16826e474dc3872b248e95f09023d81b9d9c0 Mon Sep 17 00:00:00 2001 From: crynobone Date: Thu, 28 Nov 2013 09:21:35 +0800 Subject: [PATCH 066/577] tweak exception message Signed-off-by: crynobone --- Eloquent/ModelNotFoundException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/ModelNotFoundException.php b/Eloquent/ModelNotFoundException.php index c03b232c0..8caa7acdd 100755 --- a/Eloquent/ModelNotFoundException.php +++ b/Eloquent/ModelNotFoundException.php @@ -17,7 +17,7 @@ class ModelNotFoundException extends \RuntimeException { public function setModel($model) { $this->model = $model; - $this->message = "{$model} not found"; + $this->message = "{$model} model not found"; return $this; } From 6dc0a8dc8433f949496180ad2015f0f193868c3a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 09:44:54 -0600 Subject: [PATCH 067/577] Move getDirty out of timestamp check. --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2efac23ca..4ea2e3382 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1334,13 +1334,13 @@ protected function performUpdate(Builder $query) if ($this->timestamps) { $this->updateTimestamps(); - - $dirty = $this->getDirty(); } // Once we have run the update operation, we will fire the "updated" event for // this model instance. This will allow developers to hook into these after // models are updated, giving them a chance to do any special processing. + $dirty = $this->getDirty(); + $this->setKeysForSaveQuery($query)->update($dirty); $this->fireModelEvent('updated', false); From 12cb5dedbc128b9327bcc321dc418b46a9c2379a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 10:00:10 -0600 Subject: [PATCH 068/577] Work on message, etc. --- Eloquent/ModelNotFoundException.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Eloquent/ModelNotFoundException.php b/Eloquent/ModelNotFoundException.php index 8caa7acdd..2256f1394 100755 --- a/Eloquent/ModelNotFoundException.php +++ b/Eloquent/ModelNotFoundException.php @@ -1,15 +1,16 @@ model = $model; - $this->message = "{$model} model not found"; + + $this->message = "No query results for model [{$model}]."; return $this; } /** - * Get the affected eloquent model. + * Get the affected Eloquent model. * * @return string */ From 7677a68c6aa0e0cf253515d97d545d16149be892 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 10:17:10 -0600 Subject: [PATCH 069/577] Use "fill" when creating new has one or many relation via "create". --- Eloquent/Relations/HasOneOrMany.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 819cb73ee..c45112cea 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -189,16 +189,12 @@ public function saveMany(array $models) */ public function create(array $attributes) { - $foreign = array( - $this->getPlainForeignKey() => $this->getParentKey(), - ); - // Here we will set the raw attributes to avoid hitting the "fill" method so // that we do not have to worry about a mass accessor rules blocking sets // on the models. Otherwise, some of these attributes will not get set. - $instance = $this->related->newInstance(); + $instance = $this->related->newInstance($attributes); - $instance->setRawAttributes(array_merge($attributes, $foreign)); + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); $instance->save(); From 2381ecc5e10eeea09e5679240cc916b4b3201c09 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 10:24:05 -0600 Subject: [PATCH 070/577] Doc block additions. --- Eloquent/Relations/HasManyThrough.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 056484d54..b8dd44c63 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -6,10 +6,25 @@ class HasManyThrough extends Relation { + /** + * The distance parent model instance. + * + * @var \Illuminate\Database\Eloquent\Model + */ protected $farParent; + /** + * The near key on the relationship. + * + * @var string + */ protected $firstKey; + /** + * The far key on the relationship. + * + * @var string + */ protected $secondKey; /** @@ -17,7 +32,8 @@ class HasManyThrough extends Relation { * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent - * @param string $foreignKey + * @param string $firstKey + * @param string $secondKey * @return void */ public function __construct(Builder $query, Model $farParent, Model $parent, $firstKey, $secondKey) From 75f32e17b098d1d47296e7927e1111ec5cce12e5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 11:26:26 -0600 Subject: [PATCH 071/577] Added selectRaw method to query builder. --- Query/Builder.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index 09e1aea1b..b0cc4e27c 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -196,6 +196,17 @@ public function select($columns = array('*')) return $this; } + /** + * Add a new "raw" select expression to the query. + * + * @param string $expression + * @return \Illuminate\Database\Query\Builder|static + */ + public function selectRaw($expression) + { + return $this->select(new Expression($expression)); + } + /** * Add a new select column to the query. * From 90a48857263e92a937c70e2652c8aca7fd723e59 Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Thu, 30 Jan 2014 19:57:11 +0200 Subject: [PATCH 072/577] Updated Model dirty checks to ignore numerically equivalent fields --- Eloquent/Model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 16f5dedcb..237e11543 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2548,10 +2548,16 @@ public function getDirty() foreach ($this->attributes as $key => $value) { - if ( ! array_key_exists($key, $this->original) || $value !== $this->original[$key]) + if ( ! array_key_exists($key, $this->original)) { $dirty[$key] = $value; } + else if ($value !== $this->original[$key]) { + // two equivilent numerical fields shouldn't match as 'dirty', e.g. 1 and "1" + if (!is_numeric($value) || !is_numeric($this->original[$key]) || strcmp((string) $value, (string) $this->original[$key]) != 0) { + $dirty[$key] = $value; + } + } } return $dirty; From 1566b1617c3c2af9b9ebd32fd9f9fe0297979cc2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jan 2014 12:02:46 -0600 Subject: [PATCH 073/577] Reverse if statement conditions. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 224ea2b8e..9f92af93e 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -427,7 +427,7 @@ public function onlyTrashed() */ protected function isSoftDeleteConstraint(array $where, $column) { - return $where['column'] == $column && $where['type'] == 'Null'; + return $where['type'] == 'Null' && $where['column'] == $column; } /** From 65b2aa89fa8fa82ed84340fc8ce427f0fd8f49e3 Mon Sep 17 00:00:00 2001 From: Hannes Van De Vreken Date: Thu, 30 Jan 2014 21:40:52 +0100 Subject: [PATCH 074/577] Same as #2967 but on 4.1 branch --- Eloquent/Relations/BelongsToMany.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 953951d54..dc4c9c7d3 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -928,9 +928,9 @@ public function withPivot($columns) * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function withTimestamps() + public function withTimestamps($createdAt = null, $updatedAt = null) { - return $this->withPivot($this->createdAt(), $this->updatedAt()); + return $this->withPivot($createdAt ?: $this->createdAt(), $updatedAt ?: $this->updatedAt()); } /** From d448b0f0a98daba94ab35ceb92ad8baa24821d69 Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Thu, 30 Jan 2014 23:23:43 +0200 Subject: [PATCH 075/577] Ensure there are dirty fields when performing update - just in case the updating events reset the fields --- Eloquent/Model.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 16f5dedcb..13afb85a7 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1341,9 +1341,11 @@ protected function performUpdate(Builder $query) // models are updated, giving them a chance to do any special processing. $dirty = $this->getDirty(); - $this->setKeysForSaveQuery($query)->update($dirty); + if (count($dirty) > 0) { + $this->setKeysForSaveQuery($query)->update($dirty); - $this->fireModelEvent('updated', false); + $this->fireModelEvent('updated', false); + } } return true; From 47dd4d442c1383f332bec02024aa95ba02e54588 Mon Sep 17 00:00:00 2001 From: Shhu Date: Fri, 31 Jan 2014 15:47:11 +0100 Subject: [PATCH 076/577] namespace [ErrorException] must be an instance of Blueprint, instance of Illuminate\Database\Schema\Blueprint given --- Migrations/stubs/blank.stub | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Migrations/stubs/blank.stub b/Migrations/stubs/blank.stub index 5ce40164c..a71120195 100755 --- a/Migrations/stubs/blank.stub +++ b/Migrations/stubs/blank.stub @@ -1,5 +1,6 @@ Date: Fri, 31 Jan 2014 18:15:31 +0100 Subject: [PATCH 077/577] changes and unit tests --- Query/Builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index b0cc4e27c..cf6d1adb1 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1584,12 +1584,15 @@ public function aggregate($function, $columns = array('*')) { $this->aggregate = compact('function', 'columns'); + $previousColumns = $this->columns; + $results = $this->get($columns); // Once we have executed the query, we will reset the aggregate property so // that more select queries can be executed against the database without // the aggregate value getting in the way when the grammar builds it. - $this->columns = null; $this->aggregate = null; + $this->aggregate = null; + $this->columns = $previousColumns; if (isset($results[0])) { From cc6b1d77a21b4af5b34d3187467346c2c039d5d5 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Mon, 3 Feb 2014 03:10:44 +0100 Subject: [PATCH 078/577] fix code and test --- Eloquent/Builder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 9f92af93e..b4ce10d2e 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -593,7 +593,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { if ($column instanceof Closure) { - $query = $this->model->newQuery(); + // Get a new query builder instance but avoid including any soft + // delete constraints that could mess up the nested query. + $query = $this->model->newQuery(false); call_user_func($column, $query); From 5e2b8c605ef4693a14a16411ac0e15e4e266b05f Mon Sep 17 00:00:00 2001 From: Eric Bollens Date: Fri, 31 Jan 2014 07:21:17 -0800 Subject: [PATCH 079/577] Minor clarity and type-enforcement fixes Fix Cache\TagSet::__construct() arg for prop used with array-only operations Add phpdoc @method hints for \Cache\Manager->__call to StoreInterface driver Remove unused assignment in SqlServerGrammar->compileAnsiOffset() Remove unused param from Query\Builder->orWhereBetween() Remove unused closure parameter in Connection->unprepared() Fix Database\Capsule\Manager method arg types Add explicit member var definition in Database\Capsule\Manager Fix Database\Connectors\ConnectionFactory method property type Clean up tabs and erroneous magic reference in Cache\CacheManager Change visibility of in Cookie\Queue Mark formerly implicit members as protected per #3414 --- Capsule/Manager.php | 11 +++++++++-- Connection.php | 2 +- Connectors/ConnectionFactory.php | 2 +- Query/Builder.php | 3 +-- Query/Grammars/SqlServerGrammar.php | 2 -- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index f59651463..68bb72c35 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -24,11 +24,18 @@ class Manager { * @var \Illuminate\Database\DatabaseManager */ protected $manager; + + /** + * The container instance. + * + * @var \Illuminate\Container\Container + */ + protected $container; /** * Create a new database capsule manager. * - * @param \Illuminate\Container\Container $container + * @param \Illuminate\Container\Container|null $container * @return void */ public function __construct(Container $container = null) @@ -46,7 +53,7 @@ public function __construct(Container $container = null) /** * Setup the IoC container instance. * - * @param \Illuminate\Container\Container $container + * @param \Illuminate\Container\Container|null $container * @return void */ protected function setupContainer($container) diff --git a/Connection.php b/Connection.php index 6b7cfcc16..51595b080 100755 --- a/Connection.php +++ b/Connection.php @@ -370,7 +370,7 @@ public function affectingStatement($query, $bindings = array()) */ public function unprepared($query) { - return $this->run($query, array(), function($me, $query, $bindings) + return $this->run($query, array(), function($me, $query) { if ($me->pretending()) return true; diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index 8269625a5..5d5b233b5 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -206,7 +206,7 @@ public function createConnector(array $config) * * @throws \InvalidArgumentException */ - protected function createConnection($driver, PDO $connection, $database, $prefix = '', $config = null) + protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array()) { if ($this->container->bound($key = "db.connection.{$driver}")) { diff --git a/Query/Builder.php b/Query/Builder.php index b0cc4e27c..470e3335f 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -480,10 +480,9 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa * * @param string $column * @param array $values - * @param bool $not * @return \Illuminate\Database\Query\Builder|static */ - public function orWhereBetween($column, array $values, $not = false) + public function orWhereBetween($column, array $values) { return $this->whereBetween($column, $values, 'or'); } diff --git a/Query/Grammars/SqlServerGrammar.php b/Query/Grammars/SqlServerGrammar.php index deda0b69c..944b95919 100755 --- a/Query/Grammars/SqlServerGrammar.php +++ b/Query/Grammars/SqlServerGrammar.php @@ -119,8 +119,6 @@ protected function compileAnsiOffset(Builder $query, $components) // Next we need to calculate the constraints that should be placed on the query // to get the right offset and limit from our query but if there is no limit // set we will just handle the offset only since that is all that matters. - $start = $query->offset + 1; - $constraint = $this->compileRowConstraint($query); $sql = $this->concatenate($components); From a2a27217f05c71549a7ada09548586ee2a4d5dad Mon Sep 17 00:00:00 2001 From: Steven Wade Date: Mon, 3 Feb 2014 15:43:46 -0500 Subject: [PATCH 080/577] Added support for non-numeric IDs used with Postgres --- Query/Processors/PostgresProcessor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Query/Processors/PostgresProcessor.php b/Query/Processors/PostgresProcessor.php index 10f39e7b4..bfe2b5319 100755 --- a/Query/Processors/PostgresProcessor.php +++ b/Query/Processors/PostgresProcessor.php @@ -20,8 +20,10 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu $sequence = $sequence ?: 'id'; $result = (array) $results[0]; + + $id = $result[$sequence]; - return (int) $result[$sequence]; + return is_numeric($id) ? (int) $id : $id; } /** From 991c5db31b9f8b88eb1f551d2949d2291876eb05 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 5 Feb 2014 17:34:19 -0500 Subject: [PATCH 081/577] Make getDictionary public --- Eloquent/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 6f8d591a3..c8d326fd9 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -200,7 +200,7 @@ public function unique() * @param \Illuminate\Support\Collection $collection * @return array */ - protected function getDictionary($collection) + public function getDictionary($collection) { $dictionary = array(); From 86d14f42d96c12b2073fc33996b5adad532456f4 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Fri, 7 Feb 2014 16:01:13 +0100 Subject: [PATCH 082/577] remove comment --- Eloquent/Builder.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index b4ce10d2e..35cd82701 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -593,8 +593,6 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { if ($column instanceof Closure) { - // Get a new query builder instance but avoid including any soft - // delete constraints that could mess up the nested query. $query = $this->model->newQuery(false); call_user_func($column, $query); From c3a171a9a3dc891425543ac373331c5b7417a911 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 8 Feb 2014 19:26:17 +0000 Subject: [PATCH 083/577] Fixed potential logical issues --- Query/Grammars/SqlServerGrammar.php | 4 ++-- Schema/Grammars/PostgresGrammar.php | 2 +- Schema/Grammars/SQLiteGrammar.php | 2 +- Schema/Grammars/SqlServerGrammar.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Query/Grammars/SqlServerGrammar.php b/Query/Grammars/SqlServerGrammar.php index deda0b69c..8f337b7b9 100755 --- a/Query/Grammars/SqlServerGrammar.php +++ b/Query/Grammars/SqlServerGrammar.php @@ -59,7 +59,7 @@ protected function compileColumns(Builder $query, $columns) // If there is a limit on the query, but not an offset, we will add the top // clause to the query, which serves as a "limit" type clause within the // SQL Server system similar to the limit keywords available in MySQL. - if ($query->limit > 0 and $query->offset <= 0) + if ($query->limit > 0 && $query->offset <= 0) { $select .= 'top '.$query->limit.' '; } @@ -219,4 +219,4 @@ public function getDateFormat() return 'Y-m-d H:i:s.000'; } -} \ No newline at end of file +} diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index c17057944..108f3a644 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -476,7 +476,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column) */ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) { - if (in_array($column->type, $this->serials) and $column->autoIncrement) + if (in_array($column->type, $this->serials) && $column->autoIncrement) { return ' primary key'; } diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index 09c5176bf..55a6f44cc 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -538,7 +538,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column) */ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) { - if (in_array($column->type, $this->serials) and $column->autoIncrement) + if (in_array($column->type, $this->serials) && $column->autoIncrement) { return ' primary key autoincrement'; } diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 21d1e6941..6de09bf40 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -44,8 +44,8 @@ public function compileTableExists() */ public function compileColumnExists($table) { - return "select col.name from sys.columns as col - join sys.objects as obj on col.object_id = obj.object_id + return "select col.name from sys.columns as col + join sys.objects as obj on col.object_id = obj.object_id where obj.type = 'U' and obj.name = '$table'"; } @@ -472,7 +472,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column) */ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) { - if (in_array($column->type, $this->serials) and $column->autoIncrement) + if (in_array($column->type, $this->serials) && $column->autoIncrement) { return ' identity primary key'; } From 6e4ed9924592e3c729b83545daee59e6accb56e0 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Tue, 11 Feb 2014 22:48:37 -0500 Subject: [PATCH 084/577] Update MySqlConnector.php to support Sphinx Sphinx is one of the 4 main search engines PHP has documented and provides classes for. http://www.php.net/manual/en/refs.search.php Sphinx uses the mysql protocol as an interface. The problem is when passing collate the connection to sphinx fails. The patch will not include collate in the connection if in the config file its set to null. Thank you (Original Ticket #3519) --- Connectors/MySqlConnector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index dc1b57163..269d64d19 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -26,7 +26,7 @@ public function connect(array $config) // is set on the server but needs to be set here on this client objects. $charset = $config['charset']; - $names = "set names '$charset' collate '$collation'"; + $names = "set names '$charset'".($collation!==null ? " collate '$collation'" : null); $connection->prepare($names)->execute(); @@ -72,4 +72,4 @@ protected function getDsn(array $config) return $dsn; } -} \ No newline at end of file +} From 4d3e2c7f8930c8ec00dc0785524cb753f7d42676 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 13 Feb 2014 18:37:52 -0600 Subject: [PATCH 085/577] Fix caller bug. --- Eloquent/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 16f5dedcb..652469e98 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -848,12 +848,14 @@ protected function getBelongsToManyCaller() { $self = __FUNCTION__; - return array_first(debug_backtrace(false), function($trace) use ($self) + $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self) { $caller = $trace['function']; return ( ! in_array($caller, Model::$manyMethods) && $caller != $self); }); + + return ! is_null($caller) ? $caller['function'] : null; } /** From 3035899acae38b80057c1b6579e86b385f9fdd10 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 15 Feb 2014 09:27:21 +0000 Subject: [PATCH 086/577] Fixed and updated some dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 19bbdbc49..1e2a6b375 100755 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "illuminate/filesystem": "4.1.*", "illuminate/pagination": "4.1.*", "illuminate/support": "4.1.*", - "mockery/mockery": "0.7.2", + "mockery/mockery": "0.9.*", "phpunit/phpunit": "3.7.*" }, "autoload": { From 4005f5a1bd0ed82eaf0a404ab1ca4191841fed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=BDubom=C3=ADr=20Jesze?= Date: Sat, 15 Feb 2014 12:34:34 +0100 Subject: [PATCH 087/577] Fix Illegal string offset 'function' on morphToMany --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 652469e98..430e82632 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -752,7 +752,7 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $othe // title of this relation since that is a great convention to apply. if (is_null($relation)) { - $caller = $this->getBelongsToManyCaller(); + $relation = $this->getBelongsToManyCaller(); } // First, we'll need to determine the foreign key and "other key" for the @@ -813,7 +813,7 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, return new MorphToMany( $query, $this, $name, $table, $foreignKey, - $otherKey, $caller['function'], $inverse + $otherKey, $caller, $inverse ); } From ddb589848150c707702d44291af2c60d2b0abeb0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 15 Feb 2014 11:55:02 -0600 Subject: [PATCH 088/577] Added test. --- Eloquent/Relations/BelongsToMany.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index dc4c9c7d3..80f6c8f12 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -993,4 +993,14 @@ public function getTable() return $this->table; } + /** + * Get the relationship name for the relationship. + * + * @return string + */ + public function getRelationName() + { + return $this->relationName; + } + } From 2b44c1d211b8ecaf6c1bcb3d07c2b988e624fbfb Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 17 Feb 2014 12:38:18 +0000 Subject: [PATCH 089/577] Docblock fixes --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index b0cc4e27c..e3af51ad0 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1102,7 +1102,7 @@ public function toSql() /** * Indicate that the query results should be cached. * - * @param \Carbon\Carbon|\Datetime|int $minutes + * @param \DateTime|int $minutes * @param string $key * @return \Illuminate\Database\Query\Builder|static */ From 3c5f73500ed86922f5e6029ee8f47ebc06d8f70d Mon Sep 17 00:00:00 2001 From: Martin Fjordvald Date: Tue, 18 Feb 2014 16:57:34 +0800 Subject: [PATCH 090/577] Add support for char type to the database scheme builder. SQLite internally uses only a single text type so any string function causes same internal type. The rest of the drivers all support char type. --- Schema/Blueprint.php | 12 ++++++++++++ Schema/Grammars/MySqlGrammar.php | 11 +++++++++++ Schema/Grammars/PostgresGrammar.php | 11 +++++++++++ Schema/Grammars/SQLiteGrammar.php | 13 +++++++++++++ Schema/Grammars/SqlServerGrammar.php | 12 ++++++++++++ 5 files changed, 59 insertions(+) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 26523254f..9a6ffeb1c 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -360,6 +360,18 @@ public function bigIncrements($column) return $this->unsignedBigInteger($column, true); } + /** + * Create a new char column on the table. + * + * @param string $column + * @param int $length + * @return \Illuminate\Support\Fluent + */ + public function char($column, $length = 255) + { + return $this->addColumn('char', $column, compact('length')); + } + /** * Create a new string column on the table. * diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index ceb1a22d6..1022d3b50 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -276,6 +276,17 @@ public function compileRename(Blueprint $blueprint, Fluent $command) return "rename table {$from} to ".$this->wrapTable($command->to); } + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "char({$column->length})"; + } + /** * Create the column definition for a string type. * diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index 108f3a644..f705f7d0d 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -229,6 +229,17 @@ public function compileRename(Blueprint $blueprint, Fluent $command) return "alter table {$from} rename to ".$this->wrapTable($command->to); } + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "char({$column->length})"; + } + /** * Create the column definition for a string type. * diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index 55a6f44cc..aeb43a223 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -293,6 +293,19 @@ public function compileRename(Blueprint $blueprint, Fluent $command) return "alter table {$from} rename to ".$this->wrapTable($command->to); } + /** + * Create the column definition for a char type. + * SQLite only has one internal text type and converts all char types + * to internal text type so just use varchar. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return 'varchar'; + } + /** * Create the column definition for a string type. * diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 6de09bf40..83a96ae03 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -227,6 +227,18 @@ public function compileRename(Blueprint $blueprint, Fluent $command) return "sp_rename {$from}, ".$this->wrapTable($command->to); } + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "nchar({$column->length})"; + } + + /** * Create the column definition for a string type. * From 6bc4eb46e94ae2d1c1272c41c5a91ef50065c950 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Tue, 18 Feb 2014 15:30:55 +0100 Subject: [PATCH 091/577] Fix boot on unserialize --- Eloquent/Model.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 430e82632..c9012ea1c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -239,6 +239,20 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa * @return void */ public function __construct(array $attributes = array()) + { + $this->bootIfNotBooted(); + + $this->syncOriginal(); + + $this->fill($attributes); + } + + /** + * Check if the model needs to be booted and if so, do it. + * + * @return void + */ + protected function bootIfNotBooted() { if ( ! isset(static::$booted[get_class($this)])) { @@ -250,10 +264,6 @@ public function __construct(array $attributes = array()) $this->fireModelEvent('booted', false); } - - $this->syncOriginal(); - - $this->fill($attributes); } /** @@ -2856,4 +2866,14 @@ public function __toString() return $this->toJson(); } + /** + * When a model is being unserialized, check if it needs to be booted. + * + * @return void + */ + public function __wakeup() + { + $this->bootIfNotBooted(); + } + } From 781fd4f72a2f66544e582278f46dcd0f440df117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arvid=20Bj=C3=B6rkstr=C3=B6m?= Date: Tue, 5 Nov 2013 18:06:13 +0100 Subject: [PATCH 092/577] Return an array with attached, detached and changed relationship IDs on sync --- Eloquent/Relations/BelongsToMany.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 80f6c8f12..d792194f5 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -558,10 +558,13 @@ public function createMany(array $records, array $joinings = array()) * * @param array $ids * @param bool $detaching - * @return void + * @return array Array with attached, detatched and updated relation IDs */ public function sync(array $ids, $detaching = true) { + // Keep track of what is changed + $changes = array('attached' => array(), 'detached' => array(), 'updated' => array()); + // 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 // if they exist in the array of current ones, and if not we will insert. @@ -577,14 +580,17 @@ public function sync(array $ids, $detaching = true) if ($detaching && count($detach) > 0) { $this->detach($detach); + $changes['detached'] = (array) array_walk($detach, 'intval'); } // Now we are finally ready to attach the new records. Note that we'll disable // touching until after the entire operation is complete so we don't fire a // ton of touch operations until we are totally done syncing the records. - $this->attachNew($records, $current, false); + $changes = array_merge($changes, $this->attachNew($records, $current, false)); $this->touchIfTouching(); + + return $changes; } /** @@ -616,10 +622,13 @@ protected function formatSyncList(array $records) * @param array $records * @param array $current * @param bool $touch - * @return void + * @return array Array with newly attached and updated relation IDs */ protected function attachNew(array $records, array $current, $touch = true) { + // Keep track of what is changed + $changes = array('attached' => array(), 'updated' => array()); + foreach ($records as $id => $attributes) { // If the ID is not in the list of existing pivot IDs, we will insert a new pivot @@ -628,12 +637,15 @@ protected function attachNew(array $records, array $current, $touch = true) if ( ! in_array($id, $current)) { $this->attach($id, $attributes, $touch); + $changes['attached'][] = (int) $id; } elseif (count($attributes) > 0) { $this->updateExistingPivot($id, $attributes, $touch); + $changes['updated'][] = (int) $id; } } + return $changes; } /** From b8d54462dfe93f59971900a6f3b7dca3d8312f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arvid=20Bj=C3=B6rkstr=C3=B6m?= Date: Fri, 15 Nov 2013 10:26:43 +0100 Subject: [PATCH 093/577] Updated docblock as per bencorlett's & franzliedke's suggestions --- Eloquent/Relations/BelongsToMany.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index d792194f5..10ac8c644 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -554,11 +554,12 @@ public function createMany(array $records, array $joinings = array()) } /** - * Sync the intermediate tables with a list of IDs. + * Sync the intermediate tables with a list of IDs, and return + * an array with the detached, attached and updated IDs * * @param array $ids * @param bool $detaching - * @return array Array with attached, detatched and updated relation IDs + * @return array */ public function sync(array $ids, $detaching = true) { @@ -617,12 +618,13 @@ protected function formatSyncList(array $records) } /** - * Attach all of the IDs that aren't in the current array. + * Attach all of the IDs that aren't in the current array, and return + * an array with the newly attached and updated IDs * * @param array $records * @param array $current * @param bool $touch - * @return array Array with newly attached and updated relation IDs + * @return array */ protected function attachNew(array $records, array $current, $touch = true) { From 7e5cb846762c04ada3e2d041500b100345882291 Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Thu, 20 Feb 2014 10:32:35 +1000 Subject: [PATCH 094/577] Add getter for loggingQueries --- Connection.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Connection.php b/Connection.php index 6b7cfcc16..ad6abafef 100755 --- a/Connection.php +++ b/Connection.php @@ -918,6 +918,16 @@ public function disableQueryLog() $this->loggingQueries = false; } + /** + * Determine whether we're logging queries. + * + * @return bool + */ + public function getQueryLogState() + { + return $this->loggingQueries; + } + /** * Get the name of the connected database. * From b179cf47e0b01bd7fcd642db2b0e87a0dd75be9f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 19 Feb 2014 19:38:44 -0600 Subject: [PATCH 095/577] work on query logging. --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index ad6abafef..67da0f85d 100755 --- a/Connection.php +++ b/Connection.php @@ -923,7 +923,7 @@ public function disableQueryLog() * * @return bool */ - public function getQueryLogState() + public function logging() { return $this->loggingQueries; } From 93493dec762f6582a7715ca151d56bc2d3305441 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 19 Feb 2014 19:58:18 -0600 Subject: [PATCH 096/577] remove comment. --- Schema/Grammars/SQLiteGrammar.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index aeb43a223..d0199eec3 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -295,8 +295,6 @@ public function compileRename(Blueprint $blueprint, Fluent $command) /** * Create the column definition for a char type. - * SQLite only has one internal text type and converts all char types - * to internal text type so just use varchar. * * @param \Illuminate\Support\Fluent $column * @return string From 7f2caadda666b9ce1a08b3a44fd7ebe3b47934ea Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 20 Feb 2014 15:43:47 -0500 Subject: [PATCH 097/577] Small change to follow Laravel coding style --- Eloquent/Relations/BelongsToMany.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 3395eb634..3dd909e83 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -527,10 +527,11 @@ public function createMany(array $records, array $joinings = array()) public function sync($ids, $detaching = true) { // If we have a collection of models, get the keys. - if ($ids instanceof Collection) { + if ($ids instanceof Collection) + { $ids = $ids->lists($this->otherKey); } - + // 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 // if they exist in the array of current ones, and if not we will insert. From 849b46c45b096b614ae1516fb030cd9e07baa41f Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 20 Feb 2014 17:06:15 -0500 Subject: [PATCH 098/577] Use modelKeys to retrieve relation IDs correctly instead of incorrect ->otherKey --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 3dd909e83..0ef018abb 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -529,7 +529,7 @@ public function sync($ids, $detaching = true) // If we have a collection of models, get the keys. if ($ids instanceof Collection) { - $ids = $ids->lists($this->otherKey); + $ids = $ids->modelKeys(); } // First we need to attach any of the associated models that are not currently From d6b397a9a088763b4f799145bca06efa65896330 Mon Sep 17 00:00:00 2001 From: Gabor Monori Date: Tue, 25 Feb 2014 00:15:17 +0100 Subject: [PATCH 099/577] Table prefix was missing in BelongsToMany@getRelationCountQueryForSelfJoin Table prefix was missing in BelongsToMany@getRelationCountQueryForSelfJoin --- Eloquent/Relations/BelongsToMany.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 80f6c8f12..9751521b2 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -267,7 +267,9 @@ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent { $query->select(new \Illuminate\Database\Query\Expression('count(*)')); - $query->from($this->table.' as '.$hash = $this->getRelationCountHash()); + $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); + + $query->from($this->table.' as '.$tablePrefix.$hash = $this->getRelationCountHash()); $key = $this->wrap($this->getQualifiedParentKeyName()); From ba9b89dd970efebb8f6bedab2b8f4402aa273062 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 25 Feb 2014 18:34:24 +0000 Subject: [PATCH 100/577] Use php 5.4 closures $this where safe to --- Query/Grammars/Grammar.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 4faf1d6a3..5ff74f455 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -458,13 +458,11 @@ protected function compileBasicHaving($having) */ protected function compileOrders(Builder $query, $orders) { - $me = $this; - - return 'order by '.implode(', ', array_map(function($order) use ($me) + return 'order by '.implode(', ', array_map(function($order) { if (isset($order['sql'])) return $order['sql']; - return $me->wrap($order['column']).' '.$order['direction']; + return $this->wrap($order['column']).' '.$order['direction']; } , $orders)); } From ebead45117a4ad964cb87a19c1bc5d008e6f8c3b Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 22 Feb 2014 17:49:40 -0500 Subject: [PATCH 101/577] Allow pgsql enum fields /w reserved words as names An enum with a name like `unique` would cause an SQL syntax error, so just wrapped that sucker up in double-quotes to make it work. --- Schema/Grammars/PostgresGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index f705f7d0d..6c3efbe56 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -393,7 +393,7 @@ protected function typeEnum(Fluent $column) { $allowed = array_map(function($a) { return "'".$a."'"; }, $column->allowed); - return "varchar(255) check ({$column->name} in (".implode(', ', $allowed)."))"; + return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed)."))"; } /** From fd8681f086cbd2a90bf5e0f6d0de435bda95cfbc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Feb 2014 10:55:44 -0600 Subject: [PATCH 102/577] Missing param in doc block. --- Eloquent/Relations/MorphPivot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index 85ffbc8aa..7daa0fb61 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -7,7 +7,7 @@ class MorphPivot extends Pivot { /** * Set the keys for a save update query. * - * @param \Illuminate\Database\Eloquent\Builder + * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ protected function setKeysForSaveQuery(Builder $query) From e7d15b603ae1fb440cda61fe4983d5ff24ab32c3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Feb 2014 14:57:08 -0600 Subject: [PATCH 103/577] Working on formatting. --- Eloquent/Relations/BelongsToMany.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index a6a7ad749..8f42871ee 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -556,8 +556,7 @@ public function createMany(array $records, array $joinings = array()) } /** - * Sync the intermediate tables with a list of IDs, and return - * an array with the detached, attached and updated IDs + * Sync the intermediate tables with a list of IDs. * * @param array $ids * @param bool $detaching @@ -565,8 +564,9 @@ public function createMany(array $records, array $joinings = array()) */ public function sync(array $ids, $detaching = true) { - // Keep track of what is changed - $changes = array('attached' => array(), 'detached' => array(), 'updated' => array()); + $changes = array( + 'attached' => array(), 'detached' => array(), 'updated' => array() + ); // 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 @@ -583,13 +583,16 @@ public function sync(array $ids, $detaching = true) if ($detaching && count($detach) > 0) { $this->detach($detach); + $changes['detached'] = (array) array_walk($detach, 'intval'); } // Now we are finally ready to attach the new records. Note that we'll disable // touching until after the entire operation is complete so we don't fire a // ton of touch operations until we are totally done syncing the records. - $changes = array_merge($changes, $this->attachNew($records, $current, false)); + $changes = array_merge( + $changes, $this->attachNew($records, $current, false) + ); $this->touchIfTouching(); @@ -620,8 +623,7 @@ protected function formatSyncList(array $records) } /** - * Attach all of the IDs that aren't in the current array, and return - * an array with the newly attached and updated IDs + * Attach all of the IDs that aren't in the current array. * * @param array $records * @param array $current @@ -630,7 +632,6 @@ protected function formatSyncList(array $records) */ protected function attachNew(array $records, array $current, $touch = true) { - // Keep track of what is changed $changes = array('attached' => array(), 'updated' => array()); foreach ($records as $id => $attributes) @@ -641,11 +642,13 @@ protected function attachNew(array $records, array $current, $touch = true) if ( ! in_array($id, $current)) { $this->attach($id, $attributes, $touch); + $changes['attached'][] = (int) $id; } elseif (count($attributes) > 0) { $this->updateExistingPivot($id, $attributes, $touch); + $changes['updated'][] = (int) $id; } } From c7866eb927aaa30623c166ccda9ab22332d794a7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Feb 2014 15:35:29 -0600 Subject: [PATCH 104/577] Working on code. --- Connectors/MySqlConnector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index 269d64d19..8cddc069b 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -26,7 +26,8 @@ public function connect(array $config) // is set on the server but needs to be set here on this client objects. $charset = $config['charset']; - $names = "set names '$charset'".($collation!==null ? " collate '$collation'" : null); + $names = "set names '$charset'". + ( ! is_null($collation) ? " collate '$collation'" : ''); $connection->prepare($names)->execute(); From bfde91b30cbaaa833c9602cdb1abc56ba44f2d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Can=20Geli=C5=9F?= Date: Thu, 27 Feb 2014 14:34:24 +0200 Subject: [PATCH 105/577] use php 5.4 closures see #3687 --- Eloquent/Builder.php | 12 ++++-------- Query/Builder.php | 4 +--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 5951f308f..70fbd697c 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -519,14 +519,12 @@ protected function loadRelation(array $models, $name, Closure $constraints) */ public function getRelation($relation) { - $me = $this; - // We want to run a relationship query without any constrains so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. - $query = Relation::noConstraints(function() use ($me, $relation) + $query = Relation::noConstraints(function() use ($relation) { - return $me->getModel()->$relation(); + return $this->getModel()->$relation(); }); $nested = $this->nestedRelations($relation); @@ -728,11 +726,9 @@ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) */ protected function getHasRelationQuery($relation) { - $me = $this; - - return Relation::noConstraints(function() use ($me, $relation) + return Relation::noConstraints(function() use ($relation) { - return $me->getModel()->$relation(); + return $this->getModel()->$relation(); }); } diff --git a/Query/Builder.php b/Query/Builder.php index 00af99464..4d4ee8330 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1308,9 +1308,7 @@ public function generateCacheKey() */ protected function getCacheCallback($columns) { - $me = $this; - - return function() use ($me, $columns) { return $me->getFresh($columns); }; + return function() use ($columns) { return $this->getFresh($columns); }; } /** From 84c46094263dd47a6e75fc1ca0d58bf762df9f6f Mon Sep 17 00:00:00 2001 From: Kane Cohen Date: Thu, 27 Feb 2014 23:33:50 +0000 Subject: [PATCH 106/577] Add cursor mode to DB and paginator (no conflict). --- Eloquent/Builder.php | 20 ++++++++++++++++++++ Query/Builder.php | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 70fbd697c..4b51e6679 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -269,6 +269,26 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) return $paginator->make($this->get($columns)->all(), $total, $perPage); } + /** + * Get a paginator in cursor mode for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Pagination\Paginator + */ + public function cursor($perPage = null, $columns = array('*')) + { + $paginator = $this->query->getConnection()->getPaginator(); + + $page = $paginator->getCurrentPage(); + $perPage = $perPage ?: $this->model->getPerPage(); + + // Use skip method to set correct offset and take perPage + 1 items. + $this->query->skip(($page - 1) * $perPage)->take($perPage + 1); + + return $paginator->make($this->get($columns)->all(), $perPage); + } + /** * Update a record in the database. * diff --git a/Query/Builder.php b/Query/Builder.php index 4d4ee8330..581326799 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1506,6 +1506,26 @@ public function getPaginationCount() return $total; } + /** + * Get a paginator in cursor mode for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Pagination\Paginator + */ + public function cursor($perPage = null, $columns = array('*')) + { + $paginator = $this->connection->getPaginator(); + + $page = $paginator->getCurrentPage(); + $perPage = $perPage ?: $this->model->getPerPage(); + + // Use skip method to set correct offset and take perPage + 1 items. + $this->skip(($page - 1) * $perPage)->take($perPage + 1); + + return $paginator->make($this->get($columns), $perPage); + } + /** * Determine if any rows exist for the current query. * From e3f1b60b2088656c170a03e07587c4d0b92cd39d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 27 Feb 2014 22:47:40 -0600 Subject: [PATCH 107/577] Fix bug introduced a few versions ago. --- Eloquent/Builder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 35cd82701..4a805c394 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -601,7 +601,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - $this->query->where($column, $operator, $value, $boolean); + return call_user_func_array( + array($this->query, 'where'), array_slice(func_get_args(), 0, func_num_args()) + ); } return $this; From 1eb4bfec3eab2110039def784ff1b112fd6ed974 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Fri, 28 Feb 2014 10:25:43 +0100 Subject: [PATCH 108/577] Don't return underlying query builder --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 4a805c394..e56eb53f6 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -601,7 +601,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - return call_user_func_array( + call_user_func_array( array($this->query, 'where'), array_slice(func_get_args(), 0, func_num_args()) ); } From 4457be59bb20e2b32b6a2940df9f3f38f0dc6af5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 11:04:41 -0600 Subject: [PATCH 109/577] Working on global scope system with traits. --- Eloquent/Builder.php | 138 ++++++---------- Eloquent/Model.php | 284 +++++++++++++------------------- Eloquent/Relations/Relation.php | 10 -- Eloquent/ScopeInterface.php | 21 +++ Eloquent/SoftDeletingScope.php | 152 +++++++++++++++++ Eloquent/SoftDeletingTrait.php | 142 ++++++++++++++++ 6 files changed, 480 insertions(+), 267 deletions(-) create mode 100644 Eloquent/ScopeInterface.php create mode 100644 Eloquent/SoftDeletingScope.php create mode 100644 Eloquent/SoftDeletingTrait.php diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index defc51307..9fb5ed33f 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -28,6 +28,20 @@ class Builder { */ protected $eagerLoad = array(); + /** + * All of the registered builder macros. + * + * @var array + */ + protected $macros = array(); + + /** + * A replacement for the typical delete function. + * + * @var \Closure + */ + protected $onDelete; + /** * The methods that should be returned from query builder. * @@ -332,9 +346,9 @@ protected function addUpdatedAtColumn(array $values) */ public function delete() { - if ($this->model->isSoftDeleting()) + if (isset($this->onDelete)) { - return $this->softDelete(); + return call_user_func($this->onDelete, $this); } else { @@ -343,91 +357,14 @@ public function delete() } /** - * Soft delete the record in the database. - * - * @return int - */ - protected function softDelete() - { - $column = $this->model->getDeletedAtColumn(); - - return $this->update(array($column => $this->model->freshTimestampString())); - } - - /** - * Force a delete on a set of soft deleted models. - * - * @return int - */ - public function forceDelete() - { - return $this->query->delete(); - } - - /** - * Restore the soft-deleted model instances. - * - * @return int - */ - public function restore() - { - if ($this->model->isSoftDeleting()) - { - $column = $this->model->getDeletedAtColumn(); - - return $this->update(array($column => null)); - } - } - - /** - * Include the soft deleted models in the results. - * - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function withTrashed() - { - $column = $this->model->getQualifiedDeletedAtColumn(); - - foreach ((array) $this->query->wheres as $key => $where) - { - // If the where clause is a soft delete date constraint, we will remove it from - // the query and reset the keys on the wheres. This allows this developer to - // include deleted model in a relationship result set that is lazy loaded. - if ($this->isSoftDeleteConstraint($where, $column)) - { - unset($this->query->wheres[$key]); - - $this->query->wheres = array_values($this->query->wheres); - } - } - - return $this; - } - - /** - * Force the result set to only included soft deletes. + * Register a replacement for the default delete function. * - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function onlyTrashed() - { - $this->withTrashed(); - - $this->query->whereNotNull($this->model->getQualifiedDeletedAtColumn()); - - return $this; - } - - /** - * Determine if the given where clause is a soft delete constraint. - * - * @param array $where - * @param string $column - * @return bool + * @param \Closure $callback + * @return void */ - protected function isSoftDeleteConstraint(array $where, $column) + public function onDelete(Closure $callback) { - return $where['type'] == 'Null' && $where['column'] == $column; + $this->onDelete = $callback; } /** @@ -591,7 +528,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { if ($column instanceof Closure) { - $query = $this->model->newQuery(false); + $query = $this->model->newQueryWithoutScopes(); call_user_func($column, $query); @@ -892,6 +829,29 @@ public function setModel(Model $model) return $this; } + /** + * Extend the builder with a given callback. + * + * @param string $name + * @param \Closure $callback + * @return void + */ + public function macro($name, Closure $callback) + { + $this->macros[$name] = $callback; + } + + /** + * Get the given macro by name. + * + * @param string $name + * @return \Closure + */ + public function getMacro($name) + { + return array_get($this->macros, $name); + } + /** * Dynamically handle calls into the query instance. * @@ -901,7 +861,13 @@ public function setModel(Model $model) */ public function __call($method, $parameters) { - if (method_exists($this->model, $scope = 'scope'.ucfirst($method))) + if (isset($this->macros[$method])) + { + array_unshift($parameters, $this); + + return call_user_func_array($this->macros[$method], $parameters); + } + elseif (method_exists($this->model, $scope = 'scope'.ucfirst($method))) { return $this->callScope($scope, $parameters); } diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 15ae579cf..0a720de60 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -156,13 +156,6 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ public $exists = false; - /** - * Indicates if the model should soft delete. - * - * @var bool - */ - protected $softDelete = false; - /** * Indicates whether attributes are snake cased on arrays. * @@ -191,6 +184,13 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ protected static $booted = array(); + /** + * The array of global scopes on the model. + * + * @var array + */ + protected static $globalScopes = array(); + /** * Indicates if all mass assignment is enabled. * @@ -226,13 +226,6 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ const UPDATED_AT = 'updated_at'; - /** - * The name of the "deleted at" column. - * - * @var string - */ - const DELETED_AT = 'deleted_at'; - /** * Create a new Eloquent model instance. * @@ -290,6 +283,70 @@ protected static function boot() static::$mutatorCache[$class][] = lcfirst($matches[1]); } } + + static::bootTraits(); + } + + /** + * Boot all of the bootable traits on the model. + * + * @return void + */ + protected static function bootTraits() + { + foreach (class_uses(get_called_class()) as $trait) + { + if (method_exists(get_called_class(), $method = 'boot'.class_basename($trait))) + { + forward_static_call([get_called_class(), $method]); + } + } + } + + /** + * Register a new global scope on the model. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return void + */ + public static function addGlobalScope(ScopeInterface $scope) + { + static::$globalScopes[get_called_class()][get_class($scope)] = $scope; + } + + /** + * Deteremine if a model has a global scope. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return bool + */ + public static function hasGlobalScope($scope) + { + return ! is_null(static::getGlobalScope($scope)); + } + + /** + * Get a global scope registered with the modal. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return \Illuminate\Database\Eloquent\ScopeInterface|null + */ + public static function getGlobalScope($scope) + { + return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope) + { + return $scope instanceof $registered; + }); + } + + /** + * Get the global scopes for this class instance. + * + * @return array + */ + public function getGlobalScopes() + { + return array_get(static::$globalScopes, get_class($this), []); } /** @@ -953,25 +1010,6 @@ public function delete() } } - /** - * Force a hard delete on a soft deleted model. - * - * @return void - */ - public function forceDelete() - { - $softDelete = $this->softDelete; - - // We will temporarily disable false delete to allow us to perform the real - // delete operation against the model. We will then restore the deleting - // state to what this was prior to this given hard deleting operation. - $this->softDelete = false; - - $this->delete(); - - $this->softDelete = $softDelete; - } - /** * Perform the actual delete query on this model instance. * @@ -979,48 +1017,7 @@ public function forceDelete() */ protected function performDeleteOnModel() { - $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); - - if ($this->softDelete) - { - $this->{static::DELETED_AT} = $time = $this->freshTimestamp(); - - $query->update(array(static::DELETED_AT => $this->fromDateTime($time))); - } - else - { - $query->delete(); - } - } - - /** - * Restore a soft-deleted model instance. - * - * @return bool|null - */ - public function restore() - { - if ($this->softDelete) - { - // If the restoring event does not return false, we will proceed with this - // restore operation. Otherwise, we bail out so the developer will stop - // the restore totally. We will clear the deleted timestamp and save. - if ($this->fireModelEvent('restoring') === false) - { - return false; - } - - $this->{static::DELETED_AT} = null; - - // Once we have saved the model, we will fire the "restored" event so this - // developer will do anything they need to after a restore operation is - // totally finished. Then we will return the result of the save call. - $result = $this->save(); - - $this->fireModelEvent('restored', false); - - return $result; - } + $this->newQuery()->where($this->getKeyName(), $this->getKey())->delete(); } /** @@ -1111,28 +1108,6 @@ public static function deleted($callback) static::registerModelEvent('deleted', $callback); } - /** - * Register a restoring model event with the dispatcher. - * - * @param \Closure|string $callback - * @return void - */ - public static function restoring($callback) - { - static::registerModelEvent('restoring', $callback); - } - - /** - * Register a restored model event with the dispatcher. - * - * @param \Closure|string $callback - * @return void - */ - public static function restored($callback) - { - static::registerModelEvent('restored', $callback); - } - /** * Remove all of the event listeners for the model. * @@ -1275,7 +1250,7 @@ public function push() */ public function save(array $options = array()) { - $query = $this->newQueryWithDeleted(); + $query = $this->newQueryWithoutScopes(); // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This gives an opportunities to @@ -1571,26 +1546,6 @@ public function getUpdatedAtColumn() return static::UPDATED_AT; } - /** - * Get the name of the "deleted at" column. - * - * @return string - */ - public function getDeletedAtColumn() - { - return static::DELETED_AT; - } - - /** - * Get the fully qualified "deleted at" column. - * - * @return string - */ - public function getQualifiedDeletedAtColumn() - { - return $this->getTable().'.'.$this->getDeletedAtColumn(); - } - /** * Get a fresh timestamp for the model. * @@ -1617,76 +1572,84 @@ public function freshTimestampString() * @param bool $excludeDeleted * @return \Illuminate\Database\Eloquent\Builder|static */ - public function newQuery($excludeDeleted = true) + public function newQuery() { - $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); + $builder = $this->newEloquentBuilder( + $this->newBaseQueryBuilder() + ); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model // while it is constructing and executing various queries against it. $builder->setModel($this)->with($this->with); - if ($excludeDeleted && $this->softDelete) - { - $builder->whereNull($this->getQualifiedDeletedAtColumn()); - } - - return $builder; + return $this->applyGlobalScopes($builder); } /** - * Get a new query builder that includes soft deletes. + * Get a new quer instance without a given scope. * - * @return \Illuminate\Database\Eloquent\Builder|static + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return \Illuminate\Database\Eloquent\Builder */ - public function newQueryWithDeleted() + public function newQueryWithoutScope($scope) { - return $this->newQuery(false); + $this->getGlobalScope($scope)->remove($builder = $this->newQuery(), $this); + + return $builder; } /** - * Create a new Eloquent query builder for the model. + * Get a new query builder that doesn't have any global scopes. * - * @param \Illuminate\Database\Query\Builder $query * @return \Illuminate\Database\Eloquent\Builder|static */ - public function newEloquentBuilder($query) + public function newQueryWithoutScopes() { - return new Builder($query); + return $this->removeGlobalScopes($this->newQuery()); } /** - * Determine if the model instance has been soft-deleted. + * Apply all of the global scopes to an Eloquent builder. * - * @return bool + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return \Illuminate\Database\Eloquent\Builder */ - public function trashed() + public function applyGlobalScopes($builder) { - return $this->softDelete && ! is_null($this->{static::DELETED_AT}); + foreach ($this->getGlobalScopes() as $scope) + { + $scope->apply($builder, $this); + } + + return $builder; } /** - * Get a new query builder that includes soft deletes. + * Remove all of the global scopes from an Elouqent builder. * - * @return \Illuminate\Database\Eloquent\Builder|static + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void */ - public static function withTrashed() + public function removeGlobalScopes($builder) { - return with(new static)->newQueryWithDeleted(); + foreach ($this->getGlobalScopes() as $scope) + { + $scope->remove($builder, $this); + } + + return $builder; } /** - * Get a new query builder that only includes soft deletes. + * Create a new Eloquent query builder for the model. * + * @param \Illuminate\Database\Query\Builder $query * @return \Illuminate\Database\Eloquent\Builder|static */ - public static function onlyTrashed() + public function newEloquentBuilder($query) { - $instance = new static; - - $column = $instance->getQualifiedDeletedAtColumn(); - - return $instance->newQueryWithDeleted()->whereNotNull($column); + return new Builder($query); } /** @@ -1791,27 +1754,6 @@ public function usesTimestamps() return $this->timestamps; } - /** - * Determine if the model instance uses soft deletes. - * - * @return bool - */ - public function isSoftDeleting() - { - return $this->softDelete; - } - - /** - * Set the soft deleting property on the model. - * - * @param bool $enabled - * @return void - */ - public function setSoftDeleting($enabled) - { - $this->softDelete = $enabled; - } - /** * Get the polymorphic relationship columns. * @@ -2390,7 +2332,7 @@ public function hasSetMutator($key) */ public function getDates() { - $defaults = array(static::CREATED_AT, static::UPDATED_AT, static::DELETED_AT); + $defaults = array(static::CREATED_AT, static::UPDATED_AT); return array_merge($this->dates, $defaults); } diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 403075ae4..4cd42bbfb 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -105,16 +105,6 @@ public function touch() $this->rawUpdate(array($column => $this->getRelated()->freshTimestampString())); } - /** - * Restore all of the soft deleted related models. - * - * @return int - */ - public function restore() - { - return $this->query->withTrashed()->restore(); - } - /** * Run a raw update against the base query. * diff --git a/Eloquent/ScopeInterface.php b/Eloquent/ScopeInterface.php new file mode 100644 index 000000000..e70f641b9 --- /dev/null +++ b/Eloquent/ScopeInterface.php @@ -0,0 +1,21 @@ +getModel(); + + $builder->whereNull($model->getQualifiedDeletedAtColumn()); + + $this->extend($builder); + } + + /** + * Remove the scope from the given Eloquent query builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + public function remove(Builder $builder) + { + $column = $builder->getModel()->getQualifiedDeletedAtColumn(); + + $query = $builder->getQuery(); + + foreach ((array) $query->wheres as $key => $where) + { + // If the where clause is a soft delete date constraint, we will remove it from + // the query and reset the keys on the wheres. This allows this developer to + // include deleted model in a relationship result set that is lazy loaded. + if ($this->isSoftDeleteConstraint($where, $column)) + { + unset($query->wheres[$key]); + + $query->wheres = array_values($query->wheres); + } + } + } + + /** + * Extend the query builder with the needed functions. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + public function extend(Builder $builder) + { + foreach ($this->extensions as $extension) + { + $this->{"add{$extension}"}($builder); + } + + $builder->onDelete(function(Builder $builder) + { + $column = $builder->getModel()->getDeletedAtColumn(); + + return $builder->update(array( + $column => $builder->getModel()->freshTimestampString() + )); + }); + } + + /** + * Add the force delete extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addForceDelete(Builder $builder) + { + $builder->macro('forceDelete', function(Builder $builder) + { + return $builder->getQuery()->delete(); + }); + } + + /** + * Add the restore extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addRestore(Builder $builder) + { + $builder->macro('restore', function(Builder $builder) + { + $builder->withTrashed(); + + return $builder->update(array($builder->getModel()->getDeletedAtColumn() => null)); + }); + } + + /** + * Add the with-trashed extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addWithTrashed(Builder $builder) + { + $builder->macro('withTrashed', function(Builder $builder) + { + $this->remove($builder); + + return $builder; + }); + } + + /** + * Add the only-trashed extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addOnlyTrashed(Builder $builder) + { + $builder->macro('onlyTrashed', function(Builder $builder) + { + $this->remove($builder); + + $builder->getQuery()->whereNotNull($builder->getModel()->getQualifiedDeletedAtColumn()); + + return $builder; + }); + } + + /** + * Determine if the given where clause is a soft delete constraint. + * + * @param array $where + * @param string $column + * @return bool + */ + protected function isSoftDeleteConstraint(array $where, $column) + { + return $where['type'] == 'Null' && $where['column'] == $column; + } + +} \ No newline at end of file diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php new file mode 100644 index 000000000..dc038acd3 --- /dev/null +++ b/Eloquent/SoftDeletingTrait.php @@ -0,0 +1,142 @@ +delete(); + } + + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function performDeleteOnModel() + { + $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); + + $this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp(); + + $query->update(array($this->getDeletedAtColumn() => $this->fromDateTime($time))); + } + + /** + * Restore a soft-deleted model instance. + * + * @return bool|null + */ + public function restore() + { + // If the restoring event does not return false, we will proceed with this + // restore operation. Otherwise, we bail out so the developer will stop + // the restore totally. We will clear the deleted timestamp and save. + if ($this->fireModelEvent('restoring') === false) + { + return false; + } + + $this->{$this->getDeletedAtColumn()} = null; + + // Once we have saved the model, we will fire the "restored" event so this + // developer will do anything they need to after a restore operation is + // totally finished. Then we will return the result of the save call. + $result = $this->save(); + + $this->fireModelEvent('restored', false); + + return $result; + } + + /** + * Determine if the model instance has been soft-deleted. + * + * @return bool + */ + public function trashed() + { + return ! is_null($this->{$this->getDeletedAtColumn()}); + } + + /** + * Get a new query builder that includes soft deletes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function withTrashed() + { + return with(new static)->newQueryWithoutScope(new SoftDeletingScope); + } + + /** + * Get a new query builder that only includes soft deletes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function onlyTrashed() + { + $instance = new static; + + $column = $instance->getQualifiedDeletedAtColumn(); + + return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column); + } + + /** + * Register a restoring model event with the dispatcher. + * + * @param \Closure|string $callback + * @return void + */ + public static function restoring($callback) + { + static::registerModelEvent('restoring', $callback); + } + + /** + * Register a restored model event with the dispatcher. + * + * @param \Closure|string $callback + * @return void + */ + public static function restored($callback) + { + static::registerModelEvent('restored', $callback); + } + + /** + * Get the name of the "deleted at" column. + * + * @return string + */ + public function getDeletedAtColumn() + { + return 'deleted_at'; + } + + /** + * Get the fully qualified "deleted at" column. + * + * @return string + */ + public function getQualifiedDeletedAtColumn() + { + return $this->getTable().'.'.$this->getDeletedAtColumn(); + } + +} \ No newline at end of file From 62ce3cf8d856604e705f0b901346636dda21b732 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 11:18:30 -0600 Subject: [PATCH 110/577] Fix variable typo. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 0a720de60..5150cbbce 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -335,7 +335,7 @@ public static function getGlobalScope($scope) { return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope) { - return $scope instanceof $registered; + return $scope instanceof $value; }); } From 2e53e365745b896d810f078f4aee4a6ef4657ec0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 11:37:44 -0600 Subject: [PATCH 111/577] Working out a few kinks. --- Eloquent/Builder.php | 12 +++++++++++- Eloquent/SoftDeletingTrait.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 9fb5ed33f..fdd6ee5a8 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -342,7 +342,7 @@ protected function addUpdatedAtColumn(array $values) /** * Delete a record from the database. * - * @return int + * @return mixed */ public function delete() { @@ -356,6 +356,16 @@ public function delete() } } + /** + * Run the default delete function on the builder. + * + * @return mixed + */ + public function forceDelete() + { + return $this->query->delete(); + } + /** * Register a replacement for the default delete function. * diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index dc038acd3..75e3c4548 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -2,6 +2,13 @@ trait SoftDeletingTrait { + /** + * Indicates if the model is currently force deleting. + * + * @var bool + */ + protected $forceDeleting = false; + /** * Boot the soft deleting trait for a model. * @@ -19,7 +26,11 @@ public static function bootSoftDeletingTrait() */ public function forceDelete() { - return $this->delete(); + $this->forceDeleting = true; + + $this->delete(); + + $this->forceDeleting = false; } /** @@ -28,6 +39,23 @@ public function forceDelete() * @return void */ protected function performDeleteOnModel() + { + if ($this->forceDeleting) + { + $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete(); + } + else + { + return $this->runSoftDelete(); + } + } + + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function runSoftDelete() { $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); From 9cd714f6713a37f01c22fdc78f297379b02a252c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 12:42:44 -0600 Subject: [PATCH 112/577] Simplify method. Fix bug. --- Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 4a805c394..8e93f9300 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -601,8 +601,8 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - return call_user_func_array( - array($this->query, 'where'), array_slice(func_get_args(), 0, func_num_args()) + call_user_func_array( + array($this->query, 'where'), func_get_args() ); } From 98b38a46fee774ec9794cd110661075ab30e14a0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 12:50:09 -0600 Subject: [PATCH 113/577] One line. --- Eloquent/Builder.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 8e93f9300..da3a4edac 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -601,9 +601,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - call_user_func_array( - array($this->query, 'where'), func_get_args() - ); + call_user_func_array(array($this->query, 'where'), func_get_args()); } return $this; From 1e4439f5d98ecbf4a0cc879d98c8e09b5b210295 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 28 Feb 2014 14:28:45 -0600 Subject: [PATCH 114/577] Use array_map. --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 8f42871ee..e41893b11 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -584,7 +584,7 @@ public function sync(array $ids, $detaching = true) { $this->detach($detach); - $changes['detached'] = (array) array_walk($detach, 'intval'); + $changes['detached'] = (array) array_map('intval', $detach); } // Now we are finally ready to attach the new records. Note that we'll disable From 396393bd96fe1156a35b34fec2df283405778a0a Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Sun, 2 Mar 2014 13:58:15 -0500 Subject: [PATCH 115/577] Default to current collection in getDictionary() --- Eloquent/Collection.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index c8d326fd9..f4f1752ef 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -126,7 +126,7 @@ public function modelKeys() */ public function merge($collection) { - $dictionary = $this->getDictionary($this); + $dictionary = $this->getDictionary(); foreach ($collection as $item) { @@ -189,7 +189,7 @@ public function intersect($collection) */ public function unique() { - $dictionary = $this->getDictionary($this); + $dictionary = $this->getDictionary(); return new static(array_values($dictionary)); } @@ -200,8 +200,10 @@ public function unique() * @param \Illuminate\Support\Collection $collection * @return array */ - public function getDictionary($collection) + public function getDictionary($collection = null) { + $collection = $collection ?: $this; + $dictionary = array(); foreach ($collection as $value) From 689a46b1e535c2058a219cf093674afba02edb80 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 3 Mar 2014 20:36:53 -0500 Subject: [PATCH 116/577] Fixed issue using whereHas with HasManyThrough Relationship --- Eloquent/Relations/HasManyThrough.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index b8dd44c63..22b0716da 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -2,6 +2,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Expression; use Illuminate\Database\Eloquent\Collection; class HasManyThrough extends Relation { @@ -71,9 +72,15 @@ public function addConstraints() */ public function getRelationCountQuery(Builder $query, Builder $parent) { + $parentTable = $this->parent->getTable(); + $this->setJoin($query); - return parent::getRelationCountQuery($query, $parent); + $query->select(new Expression('count(*)')); + + $key = $this->wrap($parentTable.'.'.$this->firstKey); + + return $query->where($this->getHasCompareKey(), '=', new Expression($key)); } /** From d7eb1bdd178476b6e12eb6fd56c4de6664d4dbe6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 20 Feb 2014 11:22:57 +0000 Subject: [PATCH 117/577] Updated for phpunit 4.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1e2a6b375..372efb5fe 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "illuminate/pagination": "4.1.*", "illuminate/support": "4.1.*", "mockery/mockery": "0.9.*", - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "4.0.*" }, "autoload": { "psr-0": { From 6eeaa721e842441ba3617dd357b5cd00ecf41cae Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 5 Mar 2014 19:52:20 +0100 Subject: [PATCH 118/577] Checks if a model is dirty --- Eloquent/Model.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 5150cbbce..b0e59a02b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2492,14 +2492,18 @@ public function syncOriginal() } /** - * Determine if a given attribute is dirty. + * Determine if the model is dirty or if a given attribute is dirty. * - * @param string $attribute + * @param string|null $attribute * @return bool */ - public function isDirty($attribute) + public function isDirty($attribute = null) { - return array_key_exists($attribute, $this->getDirty()); + $dirtyAttributes = $this->getDirty(); + + if (strlen($attribute) > 0) return array_key_exists($attribute, $dirtyAttributes); + + return count($dirtyAttributes) > 0; } /** From eb1010e1d0fd09d98e6e59a97954c9d7f77749e9 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 6 Mar 2014 10:15:53 +0100 Subject: [PATCH 119/577] Replace strlen() with is_null() --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b0e59a02b..baac4cb1c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2501,7 +2501,7 @@ public function isDirty($attribute = null) { $dirtyAttributes = $this->getDirty(); - if (strlen($attribute) > 0) return array_key_exists($attribute, $dirtyAttributes); + if ( ! is_null($attribute)) return array_key_exists($attribute, $dirtyAttributes); return count($dirtyAttributes) > 0; } From 577abeb5531bc9587292ec7168b2f705fe3439db Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 6 Mar 2014 10:39:12 +0100 Subject: [PATCH 120/577] use === --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index baac4cb1c..b38008ad3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2501,7 +2501,7 @@ public function isDirty($attribute = null) { $dirtyAttributes = $this->getDirty(); - if ( ! is_null($attribute)) return array_key_exists($attribute, $dirtyAttributes); + if (is_null($attribute) === false) return array_key_exists($attribute, $dirtyAttributes); return count($dirtyAttributes) > 0; } From 3a40319ecf91842e82e01c84f0028bc31d635eaa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 7 Mar 2014 22:10:30 -0600 Subject: [PATCH 121/577] Add morph type to whereHas queries on MorphToMany. Fixes #3068. --- Eloquent/Relations/MorphToMany.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 3744fd7c6..368ece748 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -64,6 +64,20 @@ protected function setWhere() return $this; } + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + $query = parent::getRelationCountQuery($query, $parent); + + return $query->where($this->table.'.'.$this->morphType, $this->morphClass); + } + /** * Set the constraints for an eager load of the relation. * From 898da225a22b1f64d8007f59909f6a013866f0ee Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Sun, 9 Mar 2014 14:42:31 -0400 Subject: [PATCH 122/577] Create a composite index for morphing columns --- Schema/Blueprint.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index f679e83fe..836d013c2 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -668,6 +668,8 @@ public function morphs($name) $this->unsignedInteger("{$name}_id"); $this->string("{$name}_type"); + + $this->index(array("{$name}_id", "{$name}_type")); } /** From 4e0ff0cc5a64d4b7137df7611a6d1d946ce6502f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 10 Mar 2014 22:28:14 -0500 Subject: [PATCH 123/577] Eager loading of MorphTo relations. This provides initial support of eager loading on morphTo relations. Constraints by type are not yet supported, but can be fairly easily added I *think*. --- Eloquent/Builder.php | 2 +- Eloquent/Model.php | 26 +++-- Eloquent/Relations/MorphTo.php | 166 ++++++++++++++++++++++++++++++++ Eloquent/Relations/Relation.php | 10 ++ 4 files changed, 197 insertions(+), 7 deletions(-) create mode 100644 Eloquent/Relations/MorphTo.php diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index da3a4edac..8c4ba23c9 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -506,7 +506,7 @@ protected function loadRelation(array $models, $name, Closure $constraints) // Once we have the results, we just match those back up to their parent models // using the relationship instance. Then we just return the finished arrays // of models which have been eagerly hydrated and are readied for return. - $results = $relation->get(); + $results = $relation->getEager(); return $relation->match($models, $results, $name); } diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c9012ea1c..17d8801f0 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Contracts\JsonableInterface; use Illuminate\Support\Contracts\ArrayableInterface; use Illuminate\Database\Eloquent\Relations\Relation; @@ -656,7 +657,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat * @param string $name * @param string $type * @param string $id - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ public function morphTo($name = null, $type = null, $id = null) { @@ -670,14 +671,27 @@ public function morphTo($name = null, $type = null, $id = null) $name = snake_case($caller['function']); } - // Next we will guess the type and ID if necessary. The type and IDs may also - // be passed into the function so that the developers may manually specify - // them on the relations. Otherwise, we will just make a great estimate. list($type, $id) = $this->getMorphs($name, $type, $id); - $class = $this->$type; + // 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 + ); + } - return $this->belongsTo($class, $id); + // 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 + { + return new MorphTo( + with(new $class)->newQuery(), $this, $id, 'id', $type, $name + ); + } } /** diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php new file mode 100644 index 000000000..09eb48eb6 --- /dev/null +++ b/Eloquent/Relations/MorphTo.php @@ -0,0 +1,166 @@ +morphType = $type; + + parent::__construct($query, $parent, $foreignKey, $otherKey, $relation); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + $this->buildDictionary($this->models = Collection::make($models)); + } + + /** + * Buiild a dictionary with the models. + * + * @param \Illuminate\Database\Eloquent\Models $models + * @return void + */ + protected function buildDictionary(Collection $models) + { + foreach ($models as $model) + { + $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}] = $model; + } + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $models; + } + + /** + * Get the results of the relationship. + * + * Called via eager load method of Eloquent query builder. + * + * @return mixed + */ + public function getEager() + { + foreach (array_keys($this->dictionary) as $type) + { + $this->matchToMorphParents($type, $this->getResultsByType($type)); + } + + return $this->models; + } + + /** + * Match the results for a given type to their parents. + * + * @param string $type + * @param \Illuminate\Database\Eloquent\Collection $results + * @return void + */ + protected function matchToMorphParents($type, Collection $results) + { + foreach ($results as $result) + { + if (isset($this->dictionary[$type][$result->getKey()])) + { + $this->dictionary[$type][$result->getKey()]->setRelation( + $this->relation, $result + ); + } + } + } + + /** + * Get all of the relation results for a type. + * + * @param string $type + * @return \Illuminate\Database\Eloquent\Collection + */ + protected function getResultsByType($type) + { + $instance = $this->createModelByType($type); + + $key = $instance->getKeyName(); + + return $instance->whereIn($key, $this->gatherKeysByType($type)->all())->get(); + } + + /** + * Gather all of the foreign keys for a given type. + * + * @param string $type + * @return array + */ + protected function gatherKeysByType($type) + { + $foreign = $this->foreignKey; + + return Collection::make($this->dictionary[$type])->map(function($model) use ($foreign) + { + return $model->{$foreign}; + }); + } + + /** + * Create a new model instance by type. + * + * @param string $type + * @return \Illuminate\Database\Eloquent\Model + */ + protected function createModelByType($type) + { + return new $type; + } + +} \ No newline at end of file diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 403075ae4..1cde2953a 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -93,6 +93,16 @@ abstract public function match(array $models, Collection $results, $relation); */ abstract public function getResults(); + /** + * Get the relationship for eager loading. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public function getEager() + { + return $this->get(); + } + /** * Touch all of the related models for the relationship. * From 071eb099e7c4f5112f80fa99fa7b047bcf110960 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 12 Mar 2014 19:50:14 -0500 Subject: [PATCH 124/577] Fix morphTo eager loading from morphMany. Added tests. --- Eloquent/Relations/MorphTo.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index 09eb48eb6..ad45516d5 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Expression; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Collection as BaseCollection; class MorphTo extends BelongsTo { @@ -67,7 +68,7 @@ protected function buildDictionary(Collection $models) { foreach ($models as $model) { - $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}] = $model; + $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; } } @@ -114,9 +115,10 @@ protected function matchToMorphParents($type, Collection $results) { if (isset($this->dictionary[$type][$result->getKey()])) { - $this->dictionary[$type][$result->getKey()]->setRelation( - $this->relation, $result - ); + foreach ($this->dictionary[$type][$result->getKey()] as $model) + { + $model->setRelation($this->relation, $result); + } } } } @@ -146,10 +148,11 @@ protected function gatherKeysByType($type) { $foreign = $this->foreignKey; - return Collection::make($this->dictionary[$type])->map(function($model) use ($foreign) + return BaseCollection::make($this->dictionary[$type])->map(function($models) use ($foreign) { - return $model->{$foreign}; - }); + return head($models)->{$foreign}; + + })->unique(); } /** @@ -158,9 +161,19 @@ protected function gatherKeysByType($type) * @param string $type * @return \Illuminate\Database\Eloquent\Model */ - protected function createModelByType($type) + public function createModelByType($type) { return new $type; } + /** + * Get the dictionary used by the relationship. + * + * @return array + */ + public function getDictionary() + { + return $this->dictionary; + } + } \ No newline at end of file From c8e6fbd9140eedd9d724d7482b8555fb075c70e4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 13 Mar 2014 11:19:40 +0800 Subject: [PATCH 125/577] add findOrNew eloquent method --- Eloquent/Model.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 17d8801f0..1bca14274 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -520,6 +520,20 @@ public static function find($id, $columns = array('*')) return $instance->newQuery()->find($id, $columns); } + /** + * Find a model by its primary key or return new static. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|Collection|static + */ + public static function findOrNew($id, $columns = array('*')) + { + if ( ! is_null($model = static::find($id, $columns))) return $model; + + return new static($columns); + } + /** * Find a model by its primary key or throw an exception. * From cd2616771b08b806d81b060466de8019378b31ff Mon Sep 17 00:00:00 2001 From: Cookie Delicious Date: Fri, 14 Mar 2014 14:57:55 -0500 Subject: [PATCH 126/577] Fix to Model MorphTo to allow for Models with custom primary key names. --- Eloquent/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 17d8801f0..55e45699c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -688,8 +688,9 @@ public function morphTo($name = null, $type = null, $id = null) // we will pass in the appropriate values so that it behaves as expected. else { + $instance = new $class; return new MorphTo( - with(new $class)->newQuery(), $this, $id, 'id', $type, $name + with($instance)->newQuery(), $this, $id, $instance->getKeyName(), $type, $name ); } } From 42b64fc815101b1d3d5a77a7bebc1bb0ae23a404 Mon Sep 17 00:00:00 2001 From: Cookie Delicious Date: Fri, 14 Mar 2014 16:31:20 -0500 Subject: [PATCH 127/577] added empty line as per note: https://github.com/laravel/framework/pull/3885 --- Eloquent/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 55e45699c..9f5473432 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -689,6 +689,7 @@ public function morphTo($name = null, $type = null, $id = null) else { $instance = new $class; + return new MorphTo( with($instance)->newQuery(), $this, $id, $instance->getKeyName(), $type, $name ); From 72c8380b9e6cb6322e3bd3c93e4ff15b1dcb5ec6 Mon Sep 17 00:00:00 2001 From: David Rushton Date: Sat, 15 Mar 2014 13:58:26 +0000 Subject: [PATCH 128/577] Added conditional to buildDictionary foreach loop Fixes situations where morphType is null --- Eloquent/Relations/MorphTo.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ad45516d5..f65cd1056 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -68,7 +68,9 @@ protected function buildDictionary(Collection $models) { foreach ($models as $model) { - $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; + if ( $model->{$this->morphType} ) { + $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; + } } } From a84c7c5052d36dc6558a16cef6c61e9c6ecd34e4 Mon Sep 17 00:00:00 2001 From: David Rushton Date: Sun, 16 Mar 2014 17:25:49 +0000 Subject: [PATCH 129/577] Updated code style --- Eloquent/Relations/MorphTo.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index f65cd1056..ac11d9fa7 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -68,7 +68,8 @@ protected function buildDictionary(Collection $models) { foreach ($models as $model) { - if ( $model->{$this->morphType} ) { + if ($model->{$this->morphType}) + { $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; } } @@ -178,4 +179,4 @@ public function getDictionary() return $this->dictionary; } -} \ No newline at end of file +} From da060d8af30d1c4cd11cd4f14100d6f7eb71b714 Mon Sep 17 00:00:00 2001 From: lazychaser Date: Tue, 18 Mar 2014 19:08:12 +0400 Subject: [PATCH 130/577] Add getMorphType() and getMorphClass() to MorphToMany --- Eloquent/Relations/MorphToMany.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 368ece748..cd669612e 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -135,4 +135,24 @@ public function newPivot(array $attributes = array(), $exists = false) return $pivot; } + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + + /** + * Get the class name of the parent model. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass; + } + } \ No newline at end of file From ab3cd0549e17993603cf91fbd669df919a904971 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 20 Mar 2014 18:59:24 +0000 Subject: [PATCH 131/577] Final cs fixes --- Capsule/Manager.php | 2 +- ConnectionInterface.php | 2 +- ConnectionResolver.php | 2 +- ConnectionResolverInterface.php | 2 +- Connectors/Connector.php | 2 +- Connectors/ConnectorInterface.php | 2 +- Connectors/PostgresConnector.php | 2 +- Connectors/SQLiteConnector.php | 2 +- Connectors/SqlServerConnector.php | 2 +- Console/Migrations/BaseCommand.php | 2 +- Console/Migrations/InstallCommand.php | 2 +- Console/Migrations/MigrateCommand.php | 2 +- Console/Migrations/RefreshCommand.php | 2 +- Console/Migrations/ResetCommand.php | 2 +- Console/Migrations/RollbackCommand.php | 2 +- Console/SeedCommand.php | 2 +- DatabaseManager.php | 2 +- DatabaseServiceProvider.php | 2 +- Eloquent/MassAssignmentException.php | 2 +- Eloquent/Relations/HasMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/HasOne.php | 2 +- Eloquent/Relations/HasOneOrMany.php | 2 +- Eloquent/Relations/MorphMany.php | 2 +- Eloquent/Relations/MorphOne.php | 2 +- Eloquent/Relations/MorphOneOrMany.php | 2 +- Eloquent/Relations/MorphTo.php | 2 +- Eloquent/Relations/MorphToMany.php | 2 +- Eloquent/Relations/Pivot.php | 4 ++-- Eloquent/Relations/Relation.php | 2 +- Grammar.php | 2 +- MigrationServiceProvider.php | 2 +- Migrations/Migration.php | 2 +- Migrations/MigrationCreator.php | 2 +- Migrations/Migrator.php | 2 +- Migrations/stubs/update.stub | 2 +- MySqlConnection.php | 2 +- PostgresConnection.php | 2 +- Query/Expression.php | 2 +- Query/Grammars/MySqlGrammar.php | 2 +- Query/Grammars/PostgresGrammar.php | 2 +- Query/JoinClause.php | 2 +- Query/Processors/PostgresProcessor.php | 4 ++-- Query/Processors/SqlServerProcessor.php | 2 +- QueryException.php | 2 +- SQLiteConnection.php | 2 +- Schema/Builder.php | 2 +- SeedServiceProvider.php | 2 +- 48 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index f59651463..d49569b8e 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -273,4 +273,4 @@ public static function __callStatic($method, $parameters) return call_user_func_array(array(static::connection(), $method), $parameters); } -} \ No newline at end of file +} diff --git a/ConnectionInterface.php b/ConnectionInterface.php index fb5282a02..f6ff5e0b5 100755 --- a/ConnectionInterface.php +++ b/ConnectionInterface.php @@ -66,4 +66,4 @@ public function statement($query, $bindings = array()); */ public function transaction(Closure $callback); -} \ No newline at end of file +} diff --git a/ConnectionResolver.php b/ConnectionResolver.php index 4312475ed..05c28e8fb 100755 --- a/ConnectionResolver.php +++ b/ConnectionResolver.php @@ -87,4 +87,4 @@ public function setDefaultConnection($name) $this->default = $name; } -} \ No newline at end of file +} diff --git a/ConnectionResolverInterface.php b/ConnectionResolverInterface.php index 7e9cfd651..46abdc037 100755 --- a/ConnectionResolverInterface.php +++ b/ConnectionResolverInterface.php @@ -25,4 +25,4 @@ public function getDefaultConnection(); */ public function setDefaultConnection($name); -} \ No newline at end of file +} diff --git a/Connectors/Connector.php b/Connectors/Connector.php index bb24034f4..90648b6f3 100755 --- a/Connectors/Connector.php +++ b/Connectors/Connector.php @@ -68,4 +68,4 @@ public function setDefaultOptions(array $options) $this->options = $options; } -} \ No newline at end of file +} diff --git a/Connectors/ConnectorInterface.php b/Connectors/ConnectorInterface.php index a3f5ea571..c2c76a5fd 100755 --- a/Connectors/ConnectorInterface.php +++ b/Connectors/ConnectorInterface.php @@ -10,4 +10,4 @@ interface ConnectorInterface { */ public function connect(array $config); -} \ No newline at end of file +} diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index dfa7d3388..8a2ff23ec 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -79,4 +79,4 @@ protected function getDsn(array $config) return $dsn; } -} \ No newline at end of file +} diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index 65c7d2beb..e73d78fb6 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -35,4 +35,4 @@ public function connect(array $config) return $this->createConnection("sqlite:{$path}", $config, $options); } -} \ No newline at end of file +} diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index df3294d2a..deb7d34d4 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -66,4 +66,4 @@ protected function getAvailableDrivers() return PDO::getAvailableDrivers(); } -} \ No newline at end of file +} diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index d4a3d5de6..7dfef5770 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -46,4 +46,4 @@ protected function getMigrationPath() return $this->laravel['path'].'/database/migrations'; } -} \ No newline at end of file +} diff --git a/Console/Migrations/InstallCommand.php b/Console/Migrations/InstallCommand.php index 09b63f439..d89c0c4af 100755 --- a/Console/Migrations/InstallCommand.php +++ b/Console/Migrations/InstallCommand.php @@ -66,4 +66,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 5a06b8764..b9c95330d 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -120,4 +120,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 2e97098ee..e3559313f 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -80,4 +80,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/ResetCommand.php b/Console/Migrations/ResetCommand.php index 386858daa..223ee40ce 100755 --- a/Console/Migrations/ResetCommand.php +++ b/Console/Migrations/ResetCommand.php @@ -81,4 +81,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/RollbackCommand.php b/Console/Migrations/RollbackCommand.php index 5d2ab4bec..8e854880b 100755 --- a/Console/Migrations/RollbackCommand.php +++ b/Console/Migrations/RollbackCommand.php @@ -76,4 +76,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index 7baf697ca..c9197e633 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -90,4 +90,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/DatabaseManager.php b/DatabaseManager.php index 2d9ee17e3..a8a7b3665 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -82,7 +82,7 @@ public function reconnect($name = null) return $this->connection($name); } - + /** * Disconnect from the given database. * diff --git a/DatabaseServiceProvider.php b/DatabaseServiceProvider.php index e91f5a5ad..492642225 100755 --- a/DatabaseServiceProvider.php +++ b/DatabaseServiceProvider.php @@ -42,4 +42,4 @@ public function register() }); } -} \ No newline at end of file +} diff --git a/Eloquent/MassAssignmentException.php b/Eloquent/MassAssignmentException.php index 9352aed3c..c7fe78e6f 100755 --- a/Eloquent/MassAssignmentException.php +++ b/Eloquent/MassAssignmentException.php @@ -1,3 +1,3 @@ matchMany($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 22b0716da..075803446 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -252,4 +252,4 @@ public function getHasCompareKey() return $this->farParent->getQualifiedKeyName(); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasOne.php b/Eloquent/Relations/HasOne.php index 69437c2ad..e4fa1517e 100755 --- a/Eloquent/Relations/HasOne.php +++ b/Eloquent/Relations/HasOne.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchOne($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 819cb73ee..1605f02e0 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -291,4 +291,4 @@ public function getQualifiedParentKeyName() return $this->parent->getTable().'.'.$this->localKey; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphMany.php b/Eloquent/Relations/MorphMany.php index 710fab5fb..85eb70a03 100755 --- a/Eloquent/Relations/MorphMany.php +++ b/Eloquent/Relations/MorphMany.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchMany($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphOne.php b/Eloquent/Relations/MorphOne.php index 9d00c539b..dad79252c 100755 --- a/Eloquent/Relations/MorphOne.php +++ b/Eloquent/Relations/MorphOne.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchOne($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index 2dff40518..c020f1b86 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -159,4 +159,4 @@ public function getMorphClass() return $this->morphClass; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ac11d9fa7..b4bae24f6 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -68,7 +68,7 @@ protected function buildDictionary(Collection $models) { foreach ($models as $model) { - if ($model->{$this->morphType}) + if ($model->{$this->morphType}) { $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; } diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index cd669612e..8ec6dad22 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -155,4 +155,4 @@ public function getMorphClass() return $this->morphClass; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/Pivot.php b/Eloquent/Relations/Pivot.php index b36aafac5..2b012975f 100755 --- a/Eloquent/Relations/Pivot.php +++ b/Eloquent/Relations/Pivot.php @@ -99,7 +99,7 @@ protected function getDeleteQuery() $query = $this->newQuery()->where($this->foreignKey, $foreign); - return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); + return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); } /** @@ -168,4 +168,4 @@ public function getUpdatedAtColumn() return $this->parent->getUpdatedAtColumn(); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 1cde2953a..2c1692252 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -295,4 +295,4 @@ public function __call($method, $parameters) return $result; } -} \ No newline at end of file +} diff --git a/Grammar.php b/Grammar.php index 32594bf03..6bb4cccf4 100755 --- a/Grammar.php +++ b/Grammar.php @@ -174,4 +174,4 @@ public function setTablePrefix($prefix) return $this; } -} \ No newline at end of file +} diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 71b3b58c2..797d7fb46 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -204,4 +204,4 @@ public function provides() ); } -} \ No newline at end of file +} diff --git a/Migrations/Migration.php b/Migrations/Migration.php index 05a6b9402..eb75d1430 100755 --- a/Migrations/Migration.php +++ b/Migrations/Migration.php @@ -19,4 +19,4 @@ public function getConnection() return $this->connection; } -} \ No newline at end of file +} diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index daf24df05..58761963a 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -168,4 +168,4 @@ public function getFilesystem() return $this->files; } -} \ No newline at end of file +} diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 386532e51..548949b2f 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -376,4 +376,4 @@ public function getFilesystem() return $this->files; } -} \ No newline at end of file +} diff --git a/Migrations/stubs/update.stub b/Migrations/stubs/update.stub index 07d3ea5ae..cc2c90437 100755 --- a/Migrations/stubs/update.stub +++ b/Migrations/stubs/update.stub @@ -31,4 +31,4 @@ class {{class}} extends Migration { }); } -} \ No newline at end of file +} diff --git a/MySqlConnection.php b/MySqlConnection.php index 5efb2718f..ac1e9d111 100755 --- a/MySqlConnection.php +++ b/MySqlConnection.php @@ -59,4 +59,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/PostgresConnection.php b/PostgresConnection.php index 3620a9b0f..56b6c4ee0 100755 --- a/PostgresConnection.php +++ b/PostgresConnection.php @@ -47,4 +47,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/Query/Expression.php b/Query/Expression.php index 82cdba6b8..68d223656 100755 --- a/Query/Expression.php +++ b/Query/Expression.php @@ -40,4 +40,4 @@ public function __toString() return (string) $this->getValue(); } -} \ No newline at end of file +} diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index c801cf84d..668588bda 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -99,4 +99,4 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } -} \ No newline at end of file +} diff --git a/Query/Grammars/PostgresGrammar.php b/Query/Grammars/PostgresGrammar.php index 8c5aac0b1..0894e1424 100755 --- a/Query/Grammars/PostgresGrammar.php +++ b/Query/Grammars/PostgresGrammar.php @@ -173,4 +173,4 @@ public function compileTruncate(Builder $query) return array('truncate '.$this->wrapTable($query->from).' restart identity' => array()); } -} \ No newline at end of file +} diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 662bea7bf..d2f7419ee 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -105,4 +105,4 @@ public function orWhere($first, $operator, $second) return $this->on($first, $operator, $second, 'or', true); } -} \ No newline at end of file +} diff --git a/Query/Processors/PostgresProcessor.php b/Query/Processors/PostgresProcessor.php index bfe2b5319..87ef3472e 100755 --- a/Query/Processors/PostgresProcessor.php +++ b/Query/Processors/PostgresProcessor.php @@ -20,7 +20,7 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu $sequence = $sequence ?: 'id'; $result = (array) $results[0]; - + $id = $result[$sequence]; return is_numeric($id) ? (int) $id : $id; @@ -37,4 +37,4 @@ public function processColumnListing($results) return array_values(array_map(function($r) { return $r->column_name; }, $results)); } -} \ No newline at end of file +} diff --git a/Query/Processors/SqlServerProcessor.php b/Query/Processors/SqlServerProcessor.php index b2d7de7f0..cfdb43263 100755 --- a/Query/Processors/SqlServerProcessor.php +++ b/Query/Processors/SqlServerProcessor.php @@ -33,4 +33,4 @@ public function processColumnListing($results) return array_values(array_map(function($r) { return $r->name; }, $results)); } -} \ No newline at end of file +} diff --git a/QueryException.php b/QueryException.php index 4146d9cad..c73dbf603 100644 --- a/QueryException.php +++ b/QueryException.php @@ -73,4 +73,4 @@ public function getBindings() return $this->bindings; } -} \ No newline at end of file +} diff --git a/SQLiteConnection.php b/SQLiteConnection.php index 5944bdc27..86603fc1e 100755 --- a/SQLiteConnection.php +++ b/SQLiteConnection.php @@ -46,4 +46,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/Schema/Builder.php b/Schema/Builder.php index 0793be5b4..51a0b4f50 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -222,4 +222,4 @@ public function blueprintResolver(Closure $resolver) $this->resolver = $resolver; } -} \ No newline at end of file +} diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index 859c9f1ef..be9291352 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -52,4 +52,4 @@ public function provides() return array('seeder', 'command.seed'); } -} \ No newline at end of file +} From 0d0e242d72b163570ea1adcac6809020413538d8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 20 Mar 2014 17:55:34 -0400 Subject: [PATCH 132/577] Added whereDay() whereMonth() and whereYear() To all the database systems I give a vague shite about --- Query/Builder.php | 60 ++++++++++++++++++++++++++++++ Query/Grammars/MySqlGrammar.php | 39 +++++++++++++++++++ Query/Grammars/PostgresGrammar.php | 39 +++++++++++++++++++ Query/Grammars/SQLiteGrammar.php | 43 +++++++++++++++++++++ 4 files changed, 181 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index e3af51ad0..4dcb7243b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -784,6 +784,66 @@ public function orWhereNotNull($column) return $this->whereNotNull($column, 'or'); } + /** + * Add a where day() between statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereDay($column, $operator, $value, $boolean = 'and') + { + $type = 'Day'; + + $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); + + $this->bindings[] = $value; + + return $this; + } + + /** + * Add a where month() between statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereMonth($column, $operator, $value, $boolean = 'and') + { + $type = 'Month'; + + $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); + + $this->bindings[] = $value; + + return $this; + } + + /** + * Add a where year() between statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereYear($column, $operator, $value, $boolean = 'and') + { + $type = 'Year'; + + $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); + + $this->bindings[] = $value; + + return $this; + } + /** * Handles dynamic "where" clauses to the query. * diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index c801cf84d..ba4acfaa1 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -99,4 +99,43 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } + /** + * Compile a "where day(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where month(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where year(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + } \ No newline at end of file diff --git a/Query/Grammars/PostgresGrammar.php b/Query/Grammars/PostgresGrammar.php index 8c5aac0b1..deee7e218 100755 --- a/Query/Grammars/PostgresGrammar.php +++ b/Query/Grammars/PostgresGrammar.php @@ -173,4 +173,43 @@ public function compileTruncate(Builder $query) return array('truncate '.$this->wrapTable($query->from).' restart identity' => array()); } + /** + * Compile a "where day(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where month(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where year(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + } \ No newline at end of file diff --git a/Query/Grammars/SQLiteGrammar.php b/Query/Grammars/SQLiteGrammar.php index aac1ad1ec..ba88b823f 100755 --- a/Query/Grammars/SQLiteGrammar.php +++ b/Query/Grammars/SQLiteGrammar.php @@ -74,4 +74,47 @@ public function compileTruncate(Builder $query) return $sql; } + /** + * Compile a "where day(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); + $value = $this->parameter($value); + + return 'strftime(\'%d\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where month(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); + $value = $this->parameter($value); + + return 'strftime(\'%m\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where year(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'strftime(\'%Y\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + } From afb8e646e38dc302bfaa620ba0d2b8132330f925 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 20 Mar 2014 18:00:50 -0400 Subject: [PATCH 133/577] MONTH() YEAR() DAY() seem common enough If 3 of the 4 are the same then it makes sense to just shove them in Grammar.php, and let SQLite be the exception. Still testing the 4 separately though, as that seems rather important. --- Query/Grammars/Grammar.php | 39 ++++++++++++++++++++++++++++++ Query/Grammars/MySqlGrammar.php | 39 ------------------------------ Query/Grammars/PostgresGrammar.php | 39 ------------------------------ 3 files changed, 39 insertions(+), 78 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 4faf1d6a3..0b6126038 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -389,6 +389,45 @@ protected function whereRaw(Builder $query, $where) return $where['sql']; } + /** + * Compile a "where day(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where month(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a "where year(field)" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + $value = $this->parameter($where['value']); + return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + /** * Compile the "group by" portions of the query. * diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index ba4acfaa1..c801cf84d 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -99,43 +99,4 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } - /** - * Compile a "where day(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereDay(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } - - /** - * Compile a "where month(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereMonth(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } - - /** - * Compile a "where year(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereYear(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } - } \ No newline at end of file diff --git a/Query/Grammars/PostgresGrammar.php b/Query/Grammars/PostgresGrammar.php index deee7e218..ef01dcd4c 100755 --- a/Query/Grammars/PostgresGrammar.php +++ b/Query/Grammars/PostgresGrammar.php @@ -172,44 +172,5 @@ public function compileTruncate(Builder $query) { return array('truncate '.$this->wrapTable($query->from).' restart identity' => array()); } - - /** - * Compile a "where day(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereDay(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } - - /** - * Compile a "where month(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereMonth(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } - - /** - * Compile a "where year(field)" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereYear(Builder $query, $where) - { - $value = $this->parameter($where['value']); - return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; - } } \ No newline at end of file From 8fe9e5ae5d97950ff7e9ee8d7f3613549d0a39ae Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 21 Mar 2014 19:36:57 +0000 Subject: [PATCH 134/577] Fixed dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a2a0ced49..2dd4eac9f 100755 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "illuminate/container": "4.2.*", "illuminate/events": "4.2.*", "illuminate/support": "4.2.*", - "nesbot/carbon": "1.*" + "nesbot/carbon": "~1.0" }, "require-dev": { "illuminate/cache": "4.2.*", From f7f7801507ac04fc3004b9c05b7cd9c2886483fc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 22 Mar 2014 11:27:31 -0500 Subject: [PATCH 135/577] DRY up various codes. Comment changes. --- Query/Builder.php | 37 +++++++++++++++-------------- Query/Grammars/Grammar.php | 40 +++++++++++++++++++++----------- Query/Grammars/SQLiteGrammar.php | 34 ++++++++++++++++++--------- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 4dcb7243b..ed4dee08a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -785,7 +785,7 @@ public function orWhereNotNull($column) } /** - * Add a where day() between statement to the query. + * Add a "where day" statement to the query. * * @param string $column * @param string $operator @@ -795,17 +795,11 @@ public function orWhereNotNull($column) */ public function whereDay($column, $operator, $value, $boolean = 'and') { - $type = 'Day'; - - $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); - - $this->bindings[] = $value; - - return $this; + return $this->addDateBasedWhere('Day', $column, $operator, $value, $boolean); } /** - * Add a where month() between statement to the query. + * Add a "where month" statement to the query. * * @param string $column * @param string $operator @@ -815,17 +809,11 @@ public function whereDay($column, $operator, $value, $boolean = 'and') */ public function whereMonth($column, $operator, $value, $boolean = 'and') { - $type = 'Month'; - - $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); - - $this->bindings[] = $value; - - return $this; + return $this->addDateBasedWhere('Month', $column, $operator, $value, $boolean); } /** - * Add a where year() between statement to the query. + * Add a "where year" statement to the query. * * @param string $column * @param string $operator @@ -835,8 +823,21 @@ public function whereMonth($column, $operator, $value, $boolean = 'and') */ public function whereYear($column, $operator, $value, $boolean = 'and') { - $type = 'Year'; + return $this->addDateBasedWhere('Year', $column, $operator, $value, $boolean); + } + /** + * Add a date based (year, month, day) statement to the query. + * + * @param string $type + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and') + { $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); $this->bindings[] = $value; diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 0b6126038..8d95942ef 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -378,54 +378,66 @@ protected function whereNotNull(Builder $query, $where) } /** - * Compile a raw where clause. + * Compile a "where day" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where * @return string */ - protected function whereRaw(Builder $query, $where) + protected function whereDay(Builder $query, $where) { - return $where['sql']; + return $this->dateBasedWhere('day', $query, $where); } /** - * Compile a "where day(field)" clause. + * Compile a "where month" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where * @return string */ - protected function whereDay(Builder $query, $where) + protected function whereMonth(Builder $query, $where) { - $value = $this->parameter($where['value']); - return 'day('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + return $this->dateBasedWhere('month', $query, $where); } /** - * Compile a "where month(field)" clause. + * Compile a "where year" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where * @return string */ - protected function whereMonth(Builder $query, $where) + protected function whereYear(Builder $query, $where) { - $value = $this->parameter($where['value']); - return 'month('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + return $this->dateBasedWhere('year', $query, $where); } /** - * Compile a "where year(field)" clause. + * Compile a date based where clause. * + * @param string $type * @param \Illuminate\Database\Query\Builder $query * @param array $where * @return string */ - protected function whereYear(Builder $query, $where) + protected function dateBasedWhere($type, Builder $query, $where) { $value = $this->parameter($where['value']); - return 'year('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + + return $type.'('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a raw where clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereRaw(Builder $query, $where) + { + return $where['sql']; } /** diff --git a/Query/Grammars/SQLiteGrammar.php b/Query/Grammars/SQLiteGrammar.php index ba88b823f..134c042c1 100755 --- a/Query/Grammars/SQLiteGrammar.php +++ b/Query/Grammars/SQLiteGrammar.php @@ -75,7 +75,7 @@ public function compileTruncate(Builder $query) } /** - * Compile a "where day(field)" clause. + * Compile a "where day" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where @@ -83,14 +83,11 @@ public function compileTruncate(Builder $query) */ protected function whereDay(Builder $query, $where) { - $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); - $value = $this->parameter($value); - - return 'strftime(\'%d\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + return $this->dateBasedWhere('%d', $query, $where); } /** - * Compile a "where month(field)" clause. + * Compile a "where month" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where @@ -98,14 +95,11 @@ protected function whereDay(Builder $query, $where) */ protected function whereMonth(Builder $query, $where) { - $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); - $value = $this->parameter($value); - - return 'strftime(\'%m\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + return $this->dateBasedWhere('%m', $query, $where); } /** - * Compile a "where year(field)" clause. + * Compile a "where year" clause. * * @param \Illuminate\Database\Query\Builder $query * @param array $where @@ -114,7 +108,25 @@ protected function whereMonth(Builder $query, $where) protected function whereYear(Builder $query, $where) { $value = $this->parameter($where['value']); + return 'strftime(\'%Y\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; } + /** + * Compile a date based where clause. + * + * @param string $type + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function dateBasedWhere($type, Builder $query, $where) + { + $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); + + $value = $this->parameter($value); + + return 'strftime(\''.$type.'\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + } From 05dad357869f03bf96421458327e42344420357e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 22 Mar 2014 11:32:27 -0500 Subject: [PATCH 136/577] DRY up more code (thanks Phil). Update change log. --- Query/Grammars/SQLiteGrammar.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Query/Grammars/SQLiteGrammar.php b/Query/Grammars/SQLiteGrammar.php index 134c042c1..b9cf671a9 100755 --- a/Query/Grammars/SQLiteGrammar.php +++ b/Query/Grammars/SQLiteGrammar.php @@ -107,9 +107,7 @@ protected function whereMonth(Builder $query, $where) */ protected function whereYear(Builder $query, $where) { - $value = $this->parameter($where['value']); - - return 'strftime(\'%Y\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + return $this->dateBasedWhere('%Y', $query, $where); } /** From b301fda3aa0de12786d5359c37e8161bc06fa1e4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 22 Mar 2014 11:40:02 -0500 Subject: [PATCH 137/577] Fix argument ordre. --- Query/Grammars/SQLiteGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Grammars/SQLiteGrammar.php b/Query/Grammars/SQLiteGrammar.php index b9cf671a9..01558d35c 100755 --- a/Query/Grammars/SQLiteGrammar.php +++ b/Query/Grammars/SQLiteGrammar.php @@ -120,7 +120,7 @@ protected function whereYear(Builder $query, $where) */ protected function dateBasedWhere($type, Builder $query, $where) { - $value = str_pad('0', $where['value'], 2, STR_PAD_LEFT); + $value = str_pad($where['value'], 2, '0', STR_PAD_LEFT); $value = $this->parameter($value); From 7dd558454992a962b58dd793f23476d77aedd533 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 22 Mar 2014 20:12:48 +0000 Subject: [PATCH 138/577] Replacement for #3940 --- Capsule/Manager.php | 2 +- ConnectionInterface.php | 2 +- ConnectionResolver.php | 2 +- ConnectionResolverInterface.php | 2 +- Connectors/Connector.php | 2 +- Connectors/ConnectorInterface.php | 2 +- Connectors/PostgresConnector.php | 2 +- Connectors/SQLiteConnector.php | 2 +- Connectors/SqlServerConnector.php | 2 +- Console/Migrations/BaseCommand.php | 2 +- Console/Migrations/InstallCommand.php | 2 +- Console/Migrations/MigrateCommand.php | 2 +- Console/Migrations/RefreshCommand.php | 2 +- Console/Migrations/ResetCommand.php | 2 +- Console/Migrations/RollbackCommand.php | 2 +- Console/SeedCommand.php | 2 +- DatabaseManager.php | 2 +- DatabaseServiceProvider.php | 2 +- Eloquent/MassAssignmentException.php | 2 +- Eloquent/Relations/HasMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/HasOne.php | 2 +- Eloquent/Relations/HasOneOrMany.php | 2 +- Eloquent/Relations/MorphMany.php | 2 +- Eloquent/Relations/MorphOne.php | 2 +- Eloquent/Relations/MorphOneOrMany.php | 2 +- Eloquent/Relations/MorphTo.php | 2 +- Eloquent/Relations/MorphToMany.php | 2 +- Eloquent/Relations/Pivot.php | 4 ++-- Eloquent/Relations/Relation.php | 2 +- Grammar.php | 2 +- MigrationServiceProvider.php | 2 +- Migrations/Migration.php | 2 +- Migrations/MigrationCreator.php | 2 +- Migrations/Migrator.php | 2 +- Migrations/stubs/update.stub | 2 +- MySqlConnection.php | 2 +- PostgresConnection.php | 2 +- Query/Expression.php | 2 +- Query/Grammars/MySqlGrammar.php | 2 +- Query/Grammars/PostgresGrammar.php | 4 ++-- Query/JoinClause.php | 2 +- Query/Processors/PostgresProcessor.php | 4 ++-- Query/Processors/SqlServerProcessor.php | 2 +- QueryException.php | 2 +- SQLiteConnection.php | 2 +- Schema/Builder.php | 2 +- SeedServiceProvider.php | 2 +- 48 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index f59651463..d49569b8e 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -273,4 +273,4 @@ public static function __callStatic($method, $parameters) return call_user_func_array(array(static::connection(), $method), $parameters); } -} \ No newline at end of file +} diff --git a/ConnectionInterface.php b/ConnectionInterface.php index fb5282a02..f6ff5e0b5 100755 --- a/ConnectionInterface.php +++ b/ConnectionInterface.php @@ -66,4 +66,4 @@ public function statement($query, $bindings = array()); */ public function transaction(Closure $callback); -} \ No newline at end of file +} diff --git a/ConnectionResolver.php b/ConnectionResolver.php index 4312475ed..05c28e8fb 100755 --- a/ConnectionResolver.php +++ b/ConnectionResolver.php @@ -87,4 +87,4 @@ public function setDefaultConnection($name) $this->default = $name; } -} \ No newline at end of file +} diff --git a/ConnectionResolverInterface.php b/ConnectionResolverInterface.php index 7e9cfd651..46abdc037 100755 --- a/ConnectionResolverInterface.php +++ b/ConnectionResolverInterface.php @@ -25,4 +25,4 @@ public function getDefaultConnection(); */ public function setDefaultConnection($name); -} \ No newline at end of file +} diff --git a/Connectors/Connector.php b/Connectors/Connector.php index bb24034f4..90648b6f3 100755 --- a/Connectors/Connector.php +++ b/Connectors/Connector.php @@ -68,4 +68,4 @@ public function setDefaultOptions(array $options) $this->options = $options; } -} \ No newline at end of file +} diff --git a/Connectors/ConnectorInterface.php b/Connectors/ConnectorInterface.php index a3f5ea571..c2c76a5fd 100755 --- a/Connectors/ConnectorInterface.php +++ b/Connectors/ConnectorInterface.php @@ -10,4 +10,4 @@ interface ConnectorInterface { */ public function connect(array $config); -} \ No newline at end of file +} diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index dfa7d3388..8a2ff23ec 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -79,4 +79,4 @@ protected function getDsn(array $config) return $dsn; } -} \ No newline at end of file +} diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index 65c7d2beb..e73d78fb6 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -35,4 +35,4 @@ public function connect(array $config) return $this->createConnection("sqlite:{$path}", $config, $options); } -} \ No newline at end of file +} diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index df3294d2a..deb7d34d4 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -66,4 +66,4 @@ protected function getAvailableDrivers() return PDO::getAvailableDrivers(); } -} \ No newline at end of file +} diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index d4a3d5de6..7dfef5770 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -46,4 +46,4 @@ protected function getMigrationPath() return $this->laravel['path'].'/database/migrations'; } -} \ No newline at end of file +} diff --git a/Console/Migrations/InstallCommand.php b/Console/Migrations/InstallCommand.php index 09b63f439..d89c0c4af 100755 --- a/Console/Migrations/InstallCommand.php +++ b/Console/Migrations/InstallCommand.php @@ -66,4 +66,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 5a06b8764..b9c95330d 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -120,4 +120,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 2e97098ee..e3559313f 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -80,4 +80,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/ResetCommand.php b/Console/Migrations/ResetCommand.php index 386858daa..223ee40ce 100755 --- a/Console/Migrations/ResetCommand.php +++ b/Console/Migrations/ResetCommand.php @@ -81,4 +81,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/Migrations/RollbackCommand.php b/Console/Migrations/RollbackCommand.php index 5d2ab4bec..8e854880b 100755 --- a/Console/Migrations/RollbackCommand.php +++ b/Console/Migrations/RollbackCommand.php @@ -76,4 +76,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index 7baf697ca..c9197e633 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -90,4 +90,4 @@ protected function getOptions() ); } -} \ No newline at end of file +} diff --git a/DatabaseManager.php b/DatabaseManager.php index 2d9ee17e3..a8a7b3665 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -82,7 +82,7 @@ public function reconnect($name = null) return $this->connection($name); } - + /** * Disconnect from the given database. * diff --git a/DatabaseServiceProvider.php b/DatabaseServiceProvider.php index e91f5a5ad..492642225 100755 --- a/DatabaseServiceProvider.php +++ b/DatabaseServiceProvider.php @@ -42,4 +42,4 @@ public function register() }); } -} \ No newline at end of file +} diff --git a/Eloquent/MassAssignmentException.php b/Eloquent/MassAssignmentException.php index 9352aed3c..c7fe78e6f 100755 --- a/Eloquent/MassAssignmentException.php +++ b/Eloquent/MassAssignmentException.php @@ -1,3 +1,3 @@ matchMany($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 22b0716da..075803446 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -252,4 +252,4 @@ public function getHasCompareKey() return $this->farParent->getQualifiedKeyName(); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasOne.php b/Eloquent/Relations/HasOne.php index 69437c2ad..e4fa1517e 100755 --- a/Eloquent/Relations/HasOne.php +++ b/Eloquent/Relations/HasOne.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchOne($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 819cb73ee..1605f02e0 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -291,4 +291,4 @@ public function getQualifiedParentKeyName() return $this->parent->getTable().'.'.$this->localKey; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphMany.php b/Eloquent/Relations/MorphMany.php index 710fab5fb..85eb70a03 100755 --- a/Eloquent/Relations/MorphMany.php +++ b/Eloquent/Relations/MorphMany.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchMany($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphOne.php b/Eloquent/Relations/MorphOne.php index 9d00c539b..dad79252c 100755 --- a/Eloquent/Relations/MorphOne.php +++ b/Eloquent/Relations/MorphOne.php @@ -44,4 +44,4 @@ public function match(array $models, Collection $results, $relation) return $this->matchOne($models, $results, $relation); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index 2dff40518..c020f1b86 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -159,4 +159,4 @@ public function getMorphClass() return $this->morphClass; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ac11d9fa7..b4bae24f6 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -68,7 +68,7 @@ protected function buildDictionary(Collection $models) { foreach ($models as $model) { - if ($model->{$this->morphType}) + if ($model->{$this->morphType}) { $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; } diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index cd669612e..8ec6dad22 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -155,4 +155,4 @@ public function getMorphClass() return $this->morphClass; } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/Pivot.php b/Eloquent/Relations/Pivot.php index b36aafac5..2b012975f 100755 --- a/Eloquent/Relations/Pivot.php +++ b/Eloquent/Relations/Pivot.php @@ -99,7 +99,7 @@ protected function getDeleteQuery() $query = $this->newQuery()->where($this->foreignKey, $foreign); - return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); + return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); } /** @@ -168,4 +168,4 @@ public function getUpdatedAtColumn() return $this->parent->getUpdatedAtColumn(); } -} \ No newline at end of file +} diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 1cde2953a..2c1692252 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -295,4 +295,4 @@ public function __call($method, $parameters) return $result; } -} \ No newline at end of file +} diff --git a/Grammar.php b/Grammar.php index 32594bf03..6bb4cccf4 100755 --- a/Grammar.php +++ b/Grammar.php @@ -174,4 +174,4 @@ public function setTablePrefix($prefix) return $this; } -} \ No newline at end of file +} diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 71b3b58c2..797d7fb46 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -204,4 +204,4 @@ public function provides() ); } -} \ No newline at end of file +} diff --git a/Migrations/Migration.php b/Migrations/Migration.php index 05a6b9402..eb75d1430 100755 --- a/Migrations/Migration.php +++ b/Migrations/Migration.php @@ -19,4 +19,4 @@ public function getConnection() return $this->connection; } -} \ No newline at end of file +} diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index daf24df05..58761963a 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -168,4 +168,4 @@ public function getFilesystem() return $this->files; } -} \ No newline at end of file +} diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 386532e51..548949b2f 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -376,4 +376,4 @@ public function getFilesystem() return $this->files; } -} \ No newline at end of file +} diff --git a/Migrations/stubs/update.stub b/Migrations/stubs/update.stub index 07d3ea5ae..cc2c90437 100755 --- a/Migrations/stubs/update.stub +++ b/Migrations/stubs/update.stub @@ -31,4 +31,4 @@ class {{class}} extends Migration { }); } -} \ No newline at end of file +} diff --git a/MySqlConnection.php b/MySqlConnection.php index 5efb2718f..ac1e9d111 100755 --- a/MySqlConnection.php +++ b/MySqlConnection.php @@ -59,4 +59,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/PostgresConnection.php b/PostgresConnection.php index 3620a9b0f..56b6c4ee0 100755 --- a/PostgresConnection.php +++ b/PostgresConnection.php @@ -47,4 +47,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/Query/Expression.php b/Query/Expression.php index 82cdba6b8..68d223656 100755 --- a/Query/Expression.php +++ b/Query/Expression.php @@ -40,4 +40,4 @@ public function __toString() return (string) $this->getValue(); } -} \ No newline at end of file +} diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index c801cf84d..668588bda 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -99,4 +99,4 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } -} \ No newline at end of file +} diff --git a/Query/Grammars/PostgresGrammar.php b/Query/Grammars/PostgresGrammar.php index ef01dcd4c..0894e1424 100755 --- a/Query/Grammars/PostgresGrammar.php +++ b/Query/Grammars/PostgresGrammar.php @@ -172,5 +172,5 @@ public function compileTruncate(Builder $query) { return array('truncate '.$this->wrapTable($query->from).' restart identity' => array()); } - -} \ No newline at end of file + +} diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 662bea7bf..d2f7419ee 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -105,4 +105,4 @@ public function orWhere($first, $operator, $second) return $this->on($first, $operator, $second, 'or', true); } -} \ No newline at end of file +} diff --git a/Query/Processors/PostgresProcessor.php b/Query/Processors/PostgresProcessor.php index bfe2b5319..87ef3472e 100755 --- a/Query/Processors/PostgresProcessor.php +++ b/Query/Processors/PostgresProcessor.php @@ -20,7 +20,7 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu $sequence = $sequence ?: 'id'; $result = (array) $results[0]; - + $id = $result[$sequence]; return is_numeric($id) ? (int) $id : $id; @@ -37,4 +37,4 @@ public function processColumnListing($results) return array_values(array_map(function($r) { return $r->column_name; }, $results)); } -} \ No newline at end of file +} diff --git a/Query/Processors/SqlServerProcessor.php b/Query/Processors/SqlServerProcessor.php index b2d7de7f0..cfdb43263 100755 --- a/Query/Processors/SqlServerProcessor.php +++ b/Query/Processors/SqlServerProcessor.php @@ -33,4 +33,4 @@ public function processColumnListing($results) return array_values(array_map(function($r) { return $r->name; }, $results)); } -} \ No newline at end of file +} diff --git a/QueryException.php b/QueryException.php index 4146d9cad..c73dbf603 100644 --- a/QueryException.php +++ b/QueryException.php @@ -73,4 +73,4 @@ public function getBindings() return $this->bindings; } -} \ No newline at end of file +} diff --git a/SQLiteConnection.php b/SQLiteConnection.php index 5944bdc27..86603fc1e 100755 --- a/SQLiteConnection.php +++ b/SQLiteConnection.php @@ -46,4 +46,4 @@ protected function getDoctrineDriver() return new DoctrineDriver; } -} \ No newline at end of file +} diff --git a/Schema/Builder.php b/Schema/Builder.php index 0793be5b4..51a0b4f50 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -222,4 +222,4 @@ public function blueprintResolver(Closure $resolver) $this->resolver = $resolver; } -} \ No newline at end of file +} diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index 859c9f1ef..be9291352 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -52,4 +52,4 @@ public function provides() return array('seeder', 'command.seed'); } -} \ No newline at end of file +} From 45d38079035ebef7361cbcd38a4b9ab00f0fc16d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 22 Mar 2014 20:29:54 +0000 Subject: [PATCH 139/577] Fixed docblocks --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9f5473432..c1c9eb5cf 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2307,6 +2307,8 @@ protected function getAttributeFromArray($key) * @param string $key * @param string $camelKey * @return mixed + * + * @throws \LogicException */ protected function getRelationshipFromMethod($key, $camelKey) { From 422ed9e658186b7d13b312f9efac615019bc591d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 23 Mar 2014 08:30:28 +0000 Subject: [PATCH 140/577] Whitespace fixes --- Eloquent/ScopeInterface.php | 2 +- Eloquent/SoftDeletingScope.php | 2 +- Eloquent/SoftDeletingTrait.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/ScopeInterface.php b/Eloquent/ScopeInterface.php index e70f641b9..b0a93a90c 100644 --- a/Eloquent/ScopeInterface.php +++ b/Eloquent/ScopeInterface.php @@ -18,4 +18,4 @@ public function apply(Builder $builder); */ public function remove(Builder $builder); -} \ No newline at end of file +} diff --git a/Eloquent/SoftDeletingScope.php b/Eloquent/SoftDeletingScope.php index 6cbaa5017..f5d1f4816 100644 --- a/Eloquent/SoftDeletingScope.php +++ b/Eloquent/SoftDeletingScope.php @@ -149,4 +149,4 @@ protected function isSoftDeleteConstraint(array $where, $column) return $where['type'] == 'Null' && $where['column'] == $column; } -} \ No newline at end of file +} diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index 75e3c4548..639a1c437 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -167,4 +167,4 @@ public function getQualifiedDeletedAtColumn() return $this->getTable().'.'.$this->getDeletedAtColumn(); } -} \ No newline at end of file +} From 1790a1de8cd568cbe042c8def4fd3b2c04064924 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 23 Mar 2014 08:36:49 +0000 Subject: [PATCH 141/577] Removed unused use statement --- Eloquent/Relations/MorphTo.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index b4bae24f6..cab45a124 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -2,7 +2,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Query\Expression; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Collection as BaseCollection; From cf949440cc25c63e237a2ef114d6c64dfc48806b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 23 Mar 2014 14:42:51 +0000 Subject: [PATCH 142/577] Eloquent relations spaces to tabs --- Eloquent/Relations/BelongsToMany.php | 4 +-- Eloquent/Relations/MorphToMany.php | 38 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index e41893b11..c81f825cb 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -840,9 +840,9 @@ public function detach($ids = array(), $touch = true) */ public function touchIfTouching() { - if ($this->touchingParent()) $this->getParent()->touch(); + if ($this->touchingParent()) $this->getParent()->touch(); - if ($this->getParent()->touches($this->relationName)) $this->touch(); + if ($this->getParent()->touches($this->relationName)) $this->touch(); } /** diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 8ec6dad22..6d8eeb1e5 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -135,24 +135,24 @@ public function newPivot(array $attributes = array(), $exists = false) return $pivot; } - /** - * Get the foreign key "type" name. - * - * @return string - */ - public function getMorphType() - { - return $this->morphType; - } - - /** - * Get the class name of the parent model. - * - * @return string - */ - public function getMorphClass() - { - return $this->morphClass; - } + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + + /** + * Get the class name of the parent model. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass; + } } From 4eba74481136c33210bf8a061411f0fbcb8094d8 Mon Sep 17 00:00:00 2001 From: J Bruni Date: Mon, 24 Mar 2014 14:06:28 -0300 Subject: [PATCH 143/577] Updated docblock for changed newQuery signature --- Eloquent/Model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 34b9dc1de..7d8cbe556 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1585,7 +1585,6 @@ public function freshTimestampString() /** * Get a new query builder for the model's table. * - * @param bool $excludeDeleted * @return \Illuminate\Database\Eloquent\Builder|static */ public function newQuery() From 13ed4faeb4e6ce06c0287bd096d9a22a7556203a Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Wed, 26 Mar 2014 09:51:48 +0100 Subject: [PATCH 144/577] Check if Seeder $command is set when resolving --- Seeder.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Seeder.php b/Seeder.php index 563426a20..cb0d939ff 100755 --- a/Seeder.php +++ b/Seeder.php @@ -54,12 +54,19 @@ protected function resolve($class) { $instance = $this->container->make($class); - return $instance->setContainer($this->container)->setCommand($this->command); + $instance->setContainer($this->container); } else { - return new $class; + $instance = new $class; } + + if (isset($this->command)) + { + $instance->setCommand($this->command); + } + + return $instance; } /** From 4601687b8431b97b3eaf223488e176bb45c247a0 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Wed, 1 Jan 2014 21:48:57 +0100 Subject: [PATCH 145/577] separate query bindings --- Query/Builder.php | 69 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 60d0b9943..6ec3bc53b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -34,7 +34,12 @@ class Builder { * * @var array */ - protected $bindings = array(); + protected $bindings = array( + 'select' => array(), + 'where' => array(), + 'having' => array(), + 'order' => array(), + ); /** * An aggregate function and column to be run. @@ -391,7 +396,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' if ( ! $value instanceof Expression) { - $this->bindings[] = $value; + $this->bindings['where'][] = $value; } return $this; @@ -438,7 +443,7 @@ public function whereRaw($sql, array $bindings = array(), $boolean = 'and') $this->wheres[] = compact('type', 'sql', 'boolean'); - $this->bindings = array_merge($this->bindings, $bindings); + $this->bindings['where'] = array_merge($this->bindings['where'], $bindings); return $this; } @@ -470,7 +475,7 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa $this->wheres[] = compact('column', 'type', 'boolean', 'not'); - $this->bindings = array_merge($this->bindings, $values); + $this->bindings['where'] = array_merge($this->bindings['where'], $values); return $this; } @@ -666,7 +671,7 @@ public function whereIn($column, $values, $boolean = 'and', $not = false) $this->wheres[] = compact('type', 'column', 'values', 'boolean'); - $this->bindings = array_merge($this->bindings, $values); + $this->bindings['where'] = array_merge($this->bindings['where'], $values); return $this; } @@ -935,7 +940,7 @@ public function having($column, $operator = null, $value = null) $this->havings[] = compact('type', 'column', 'operator', 'value'); - $this->bindings[] = $value; + $this->bindings['having'][] = $value; return $this; } @@ -954,7 +959,7 @@ public function havingRaw($sql, array $bindings = array(), $boolean = 'and') $this->havings[] = compact('type', 'sql', 'boolean'); - $this->bindings = array_merge($this->bindings, $bindings); + $this->bindings['having'] = array_merge($this->bindings['having'], $bindings); return $this; } @@ -1022,7 +1027,7 @@ public function orderByRaw($sql, $bindings = array()) $this->orders[] = compact('type', 'sql'); - $this->bindings = array_merge($this->bindings, $bindings); + $this->bindings['order'] = array_merge($this->bindings['order'], $bindings); return $this; } @@ -1282,7 +1287,7 @@ public function getFresh($columns = array('*')) */ protected function runSelect() { - return $this->connection->select($this->toSql(), $this->bindings); + return $this->connection->select($this->toSql(), $this->getBindings()); } /** @@ -1358,7 +1363,7 @@ public function generateCacheKey() { $name = $this->connection->getName(); - return md5($name.$this->toSql().serialize($this->bindings)); + return md5($name.$this->toSql().serialize($this->getBindings())); } /** @@ -1729,7 +1734,7 @@ public function insertGetId(array $values, $sequence = null) */ public function update(array $values) { - $bindings = array_values(array_merge($values, $this->bindings)); + $bindings = array_values(array_merge($values, $this->getBindings())); $sql = $this->grammar->compileUpdate($this, $values); @@ -1785,7 +1790,7 @@ public function delete($id = null) $sql = $this->grammar->compileDelete($this); - return $this->connection->delete($sql, $this->bindings); + return $this->connection->delete($sql, $this->getBindings()); } /** @@ -1822,7 +1827,7 @@ public function mergeWheres($wheres, $bindings) { $this->wheres = array_merge((array) $this->wheres, (array) $wheres); - $this->bindings = array_values(array_merge($this->bindings, (array) $bindings)); + $this->bindings['where'] = array_values(array_merge($this->bindings['where'], (array) $bindings)); } /** @@ -1851,11 +1856,21 @@ public function raw($value) } /** - * Get the current query value bindings. + * Get the current query value bindings in a flattened array. * * @return array */ public function getBindings() + { + return array_flatten($this->bindings); + } + + /** + * Get the raw array of bindings. + * + * @return array + */ + public function getRawBindings() { return $this->bindings; } @@ -1863,12 +1878,18 @@ public function getBindings() /** * Set the bindings on the query builder. * - * @param array $bindings + * @param array $bindings + * @param string $type * @return \Illuminate\Database\Query\Builder */ - public function setBindings(array $bindings) + public function setBindings(array $bindings, $type = 'where') { - $this->bindings = $bindings; + if (!array_key_exists($type, $this->bindings)) + { + throw new \InvalidArgumentException("Invalid binding type: $type"); + } + + $this->bindings[$type] = $bindings; return $this; } @@ -1876,12 +1897,18 @@ public function setBindings(array $bindings) /** * Add a binding to the query. * - * @param mixed $value + * @param mixed $value + * @param string $type * @return \Illuminate\Database\Query\Builder */ - public function addBinding($value) + public function addBinding($value, $type = 'where') { - $this->bindings[] = $value; + if (!array_key_exists($type, $this->bindings)) + { + throw new \InvalidArgumentException("Invalid binding type: $type"); + } + + $this->bindings[$type][] = $value; return $this; } @@ -1894,7 +1921,7 @@ public function addBinding($value) */ public function mergeBindings(Builder $query) { - $this->bindings = array_values(array_merge($this->bindings, $query->bindings)); + $this->bindings = array_merge_recursive($this->bindings, $query->bindings); return $this; } From 16b1e49f02c89551cdb38542f54694b8cf898344 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 2 Jan 2014 09:38:41 +0100 Subject: [PATCH 146/577] clean up code and formatting --- Query/Builder.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 6ec3bc53b..6ffc58d08 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -396,7 +396,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' if ( ! $value instanceof Expression) { - $this->bindings['where'][] = $value; + $this->addBinding($value, 'where'); } return $this; @@ -443,7 +443,7 @@ public function whereRaw($sql, array $bindings = array(), $boolean = 'and') $this->wheres[] = compact('type', 'sql', 'boolean'); - $this->bindings['where'] = array_merge($this->bindings['where'], $bindings); + $this->addBinding($bindings, 'where'); return $this; } @@ -475,7 +475,7 @@ public function whereBetween($column, array $values, $boolean = 'and', $not = fa $this->wheres[] = compact('column', 'type', 'boolean', 'not'); - $this->bindings['where'] = array_merge($this->bindings['where'], $values); + $this->addBinding($values, 'where'); return $this; } @@ -671,7 +671,7 @@ public function whereIn($column, $values, $boolean = 'and', $not = false) $this->wheres[] = compact('type', 'column', 'values', 'boolean'); - $this->bindings['where'] = array_merge($this->bindings['where'], $values); + $this->addBinding($values, 'where'); return $this; } @@ -940,7 +940,7 @@ public function having($column, $operator = null, $value = null) $this->havings[] = compact('type', 'column', 'operator', 'value'); - $this->bindings['having'][] = $value; + $this->addBinding($value, 'having'); return $this; } @@ -959,7 +959,7 @@ public function havingRaw($sql, array $bindings = array(), $boolean = 'and') $this->havings[] = compact('type', 'sql', 'boolean'); - $this->bindings['having'] = array_merge($this->bindings['having'], $bindings); + $this->addBinding($bindings, 'having'); return $this; } @@ -1027,7 +1027,7 @@ public function orderByRaw($sql, $bindings = array()) $this->orders[] = compact('type', 'sql'); - $this->bindings['order'] = array_merge($this->bindings['order'], $bindings); + $this->addBinding($bindings, 'order'); return $this; } @@ -1884,7 +1884,7 @@ public function getRawBindings() */ public function setBindings(array $bindings, $type = 'where') { - if (!array_key_exists($type, $this->bindings)) + if ( ! array_key_exists($type, $this->bindings)) { throw new \InvalidArgumentException("Invalid binding type: $type"); } @@ -1903,12 +1903,19 @@ public function setBindings(array $bindings, $type = 'where') */ public function addBinding($value, $type = 'where') { - if (!array_key_exists($type, $this->bindings)) + if ( ! array_key_exists($type, $this->bindings)) { throw new \InvalidArgumentException("Invalid binding type: $type"); } - $this->bindings[$type][] = $value; + if (is_array($value)) + { + $this->bindings[$type] = array_values(array_merge($this->bindings[$type], $value)); + } + else + { + $this->bindings[$type][] = $value; + } return $this; } From e614611f9fdf8fcf3c34ad11a612be56c8309fd9 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 6 Feb 2014 15:39:49 +0100 Subject: [PATCH 147/577] fix join binding order --- Query/Builder.php | 5 +++-- Query/JoinClause.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 6ffc58d08..e1d05b86b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -36,9 +36,10 @@ class Builder { */ protected $bindings = array( 'select' => array(), - 'where' => array(), + 'join' => array(), + 'where' => array(), 'having' => array(), - 'order' => array(), + 'order' => array(), ); /** diff --git a/Query/JoinClause.php b/Query/JoinClause.php index d2f7419ee..76b84c861 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -59,7 +59,7 @@ public function on($first, $operator, $second, $boolean = 'and', $where = false) { $this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where'); - if ($where) $this->query->addBinding($second); + if ($where) $this->query->addBinding($second, 'join'); return $this; } From d03c8a5ab3dcec91951be486640ea97601bfd06c Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 27 Mar 2014 10:27:49 +0100 Subject: [PATCH 148/577] update addDateBasedWhere to use addBinding --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index e1d05b86b..b60fbd202 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -846,7 +846,7 @@ protected function addDateBasedWhere($type, $column, $operator, $value, $boolean { $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); - $this->bindings[] = $value; + $this->addBinding($value, 'where'); return $this; } From ab338b1ab416b8c7ad0b6e8e0ed955e88aa4d995 Mon Sep 17 00:00:00 2001 From: Scot Lawrie Date: Thu, 3 Apr 2014 14:52:39 -0400 Subject: [PATCH 149/577] Fix compileDelete() PHPDoc comment --- Query/Grammars/Grammar.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 00b13c04e..9f37425e6 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -666,7 +666,6 @@ public function compileUpdate(Builder $query, $values) * Compile a delete statement into SQL. * * @param \Illuminate\Database\Query\Builder $query - * @param array $values * @return string */ public function compileDelete(Builder $query) From 5a6f7e6addf72bcef480dc246f172ec5544a8530 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 8 Mar 2014 10:27:06 +0100 Subject: [PATCH 150/577] remove find, findOrFail from model, delegate to query builder --- Eloquent/Builder.php | 2 ++ Eloquent/Model.php | 32 -------------------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 8c4ba23c9..dd18553d9 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,6 +77,8 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { + if (empty($id)) return new Collection; + $this->query->whereIn($this->model->getKeyName(), $id); return $this->get($columns); diff --git a/Eloquent/Model.php b/Eloquent/Model.php index df44e5e81..835346f17 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -504,22 +504,6 @@ public static function all($columns = array('*')) return $instance->newQuery()->get($columns); } - /** - * Find a model by its primary key. - * - * @param mixed $id - * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|Collection|static - */ - public static function find($id, $columns = array('*')) - { - if (is_array($id) && empty($id)) return new Collection; - - $instance = new static; - - return $instance->newQuery()->find($id, $columns); - } - /** * Find a model by its primary key or return new static. * @@ -534,22 +518,6 @@ public static function findOrNew($id, $columns = array('*')) return new static($columns); } - /** - * Find a model by its primary key or throw an exception. - * - * @param mixed $id - * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|Collection|static - * - * @throws ModelNotFoundException - */ - public static function findOrFail($id, $columns = array('*')) - { - if ( ! is_null($model = static::find($id, $columns))) return $model; - - throw with(new ModelNotFoundException)->setModel(get_called_class()); - } - /** * Eager load relations on the model. * From 5d149818665a5b0e83a92082a564fed9f00dce23 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 8 Mar 2014 10:31:33 +0100 Subject: [PATCH 151/577] use model->newCollection --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index dd18553d9..0ca913cd1 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,7 +77,7 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { - if (empty($id)) return new Collection; + if (empty($id)) return $this->model->newCollection(); $this->query->whereIn($this->model->getKeyName(), $id); From c4d63e78f28c5197c2b8fcaa1ab6146caa84aee1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 13:40:16 -0500 Subject: [PATCH 152/577] Work on quick pagination for larger data-sets. This provides support for running pagination without a separate count query for data-sets that do not need page numbers. --- Eloquent/Builder.php | 9 ++++++--- Query/Builder.php | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index a9dc79c31..01d5bc8b9 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -284,20 +284,23 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) } /** - * Get a paginator in cursor mode for the "select" statement. + * Get a paginator only supporting simple next and previous links. * + * This is more efficient on larger data-sets, etc. + * + * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function cursor($perPage = null, $columns = array('*')) + public function quickPaginate($perPage = null, $columns = array('*')) { $paginator = $this->query->getConnection()->getPaginator(); $page = $paginator->getCurrentPage(); + $perPage = $perPage ?: $this->model->getPerPage(); - // Use skip method to set correct offset and take perPage + 1 items. $this->query->skip(($page - 1) * $perPage)->take($perPage + 1); return $paginator->make($this->get($columns)->all(), $perPage); diff --git a/Query/Builder.php b/Query/Builder.php index ecb25f06b..5ffa79c97 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1568,20 +1568,22 @@ public function getPaginationCount() } /** - * Get a paginator in cursor mode for the "select" statement. + * Get a paginator only supporting simple next and previous links. + * + * This is more efficient on larger data-sets, etc. * * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function cursor($perPage = null, $columns = array('*')) + public function quickPaginate($perPage = null, $columns = array('*')) { $paginator = $this->connection->getPaginator(); $page = $paginator->getCurrentPage(); + $perPage = $perPage ?: $this->model->getPerPage(); - // Use skip method to set correct offset and take perPage + 1 items. $this->skip(($page - 1) * $perPage)->take($perPage + 1); return $paginator->make($this->get($columns), $perPage); From ab481dd820347c4f439f2779db5a391363a16a65 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 14:06:47 -0500 Subject: [PATCH 153/577] Simple paginate method rename. --- Eloquent/Builder.php | 2 +- Query/Builder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 01d5bc8b9..062a997f1 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -293,7 +293,7 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function quickPaginate($perPage = null, $columns = array('*')) + public function simplePaginate($perPage = null, $columns = array('*')) { $paginator = $this->query->getConnection()->getPaginator(); diff --git a/Query/Builder.php b/Query/Builder.php index 5ffa79c97..1e4a081ef 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1576,7 +1576,7 @@ public function getPaginationCount() * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function quickPaginate($perPage = null, $columns = array('*')) + public function simplePaginate($perPage = null, $columns = array('*')) { $paginator = $this->connection->getPaginator(); From 10933848aa790c429e2d33d5a04aafc5270b5113 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 14:28:17 -0500 Subject: [PATCH 154/577] Throw exception when no primary key and deleting. --- Eloquent/Model.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index df44e5e81..e0dcd2806 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -960,6 +960,11 @@ public static function destroy($ids) */ public function delete() { + if (is_null($this->primaryKey)) + { + throw new \Exception("No primary key defined on model."); + } + if ($this->exists) { if ($this->fireModelEvent('deleting') === false) return false; From 7f327152a501520148f4c3f21cd651697dcc50c0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 15:43:02 -0500 Subject: [PATCH 155/577] Turn the count into an expression. --- Eloquent/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 8c4ba23c9..c177e2e06 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -696,6 +696,8 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, { $this->mergeWheresToHas($hasQuery, $relation); + $count = new Expression((int) $count); + return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean); } From e443597b0a694678f1bdeeed2df1522c18af80a7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 15:44:41 -0500 Subject: [PATCH 156/577] Remove the count. --- Eloquent/Builder.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index c177e2e06..8c4ba23c9 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -696,8 +696,6 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, { $this->mergeWheresToHas($hasQuery, $relation); - $count = new Expression((int) $count); - return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean); } From 32238ec59a7424592c46876d93a7c59216eeca7a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Apr 2014 15:56:01 -0500 Subject: [PATCH 157/577] Fix expression. --- Eloquent/Builder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 8c4ba23c9..1f4c9e76c 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -696,6 +696,11 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, { $this->mergeWheresToHas($hasQuery, $relation); + if (is_numeric($count)) + { + $count = new Expression($count); + } + return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean); } From 09700c94a67fef540c6bfa0aa4c58fb0a33c4cde Mon Sep 17 00:00:00 2001 From: Kevin Simard Date: Mon, 7 Apr 2014 12:53:48 -0700 Subject: [PATCH 158/577] Add events firing in transaction. Signed-off-by: Kevin Simard --- Connection.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Connection.php b/Connection.php index 0ee1de06b..12bdadea0 100755 --- a/Connection.php +++ b/Connection.php @@ -454,6 +454,11 @@ public function beginTransaction() { $this->pdo->beginTransaction(); } + + if (isset($this->events)) + { + $this->events->fire('connection.beganTransaction', $this); + } } /** @@ -466,6 +471,11 @@ public function commit() if ($this->transactions == 1) $this->pdo->commit(); --$this->transactions; + + if (isset($this->events)) + { + $this->events->fire('connection.commited', $this); + } } /** @@ -485,6 +495,11 @@ public function rollBack() { --$this->transactions; } + + if (isset($this->events)) + { + $this->events->fire('connection.rollBacked', $this); + } } /** @@ -878,6 +893,16 @@ public function setFetchMode($fetchMode) $this->fetchMode = $fetchMode; } + /** + * Get the number of active transactions. + * + * @return int + */ + public function getTransactions() + { + return $this->transactions; + } + /** * Get the connection query log. * From 528c7b3d6882d20330965a6cb79f0570c8417aa4 Mon Sep 17 00:00:00 2001 From: Andrej Badin Date: Mon, 7 Apr 2014 22:19:16 +0200 Subject: [PATCH 159/577] Fix `count` method return value. Return number represented as integer instead of string. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 2f9a3ab32..264b672a7 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1586,7 +1586,7 @@ public function exists() */ public function count($column = '*') { - return $this->aggregate(__FUNCTION__, array($column)); + return (int)$this->aggregate(__FUNCTION__, array($column)); } /** From 8f823fad2e877bd4259a3fcb867b5ff4b4132d22 Mon Sep 17 00:00:00 2001 From: Andrej Badin Date: Mon, 7 Apr 2014 23:36:14 +0200 Subject: [PATCH 160/577] Add space between type-casting operator and return value. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 264b672a7..68f0031df 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1586,7 +1586,7 @@ public function exists() */ public function count($column = '*') { - return (int)$this->aggregate(__FUNCTION__, array($column)); + return (int) $this->aggregate(__FUNCTION__, array($column)); } /** From 1aba1f6841115af13250e25f8ab2706319a66d69 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 8 Apr 2014 15:41:49 -0500 Subject: [PATCH 161/577] Revert "use model->newCollection" This reverts commit 26e5809a68464387b1544e2d614354f73fc72b07. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 04e61fc7f..d7d888ff6 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,7 +77,7 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { - if (empty($id)) return $this->model->newCollection(); + if (empty($id)) return new Collection; $this->query->whereIn($this->model->getKeyName(), $id); From 2ae5ad03ad95c7447dbef3112a7d8aaba275a70e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 8 Apr 2014 15:41:57 -0500 Subject: [PATCH 162/577] Revert "remove find, findOrFail from model, delegate to query builder" This reverts commit 7f8b07c5b338d071606d4b9b0acf2d956ae2ef4e. --- Eloquent/Builder.php | 2 -- Eloquent/Model.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index d7d888ff6..1f4c9e76c 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,8 +77,6 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { - if (empty($id)) return new Collection; - $this->query->whereIn($this->model->getKeyName(), $id); return $this->get($columns); diff --git a/Eloquent/Model.php b/Eloquent/Model.php index f294ef69d..e0dcd2806 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -504,6 +504,22 @@ public static function all($columns = array('*')) return $instance->newQuery()->get($columns); } + /** + * Find a model by its primary key. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|Collection|static + */ + public static function find($id, $columns = array('*')) + { + if (is_array($id) && empty($id)) return new Collection; + + $instance = new static; + + return $instance->newQuery()->find($id, $columns); + } + /** * Find a model by its primary key or return new static. * @@ -518,6 +534,22 @@ public static function findOrNew($id, $columns = array('*')) return new static($columns); } + /** + * Find a model by its primary key or throw an exception. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|Collection|static + * + * @throws ModelNotFoundException + */ + public static function findOrFail($id, $columns = array('*')) + { + if ( ! is_null($model = static::find($id, $columns))) return $model; + + throw with(new ModelNotFoundException)->setModel(get_called_class()); + } + /** * Eager load relations on the model. * From 791b3b0d94d66b76e67eec7908301402d496a9b8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 8 Apr 2014 15:43:47 -0500 Subject: [PATCH 163/577] Add back new collection. --- Eloquent/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 1f4c9e76c..d7d888ff6 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,6 +77,8 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { + if (empty($id)) return new Collection; + $this->query->whereIn($this->model->getKeyName(), $id); return $this->get($columns); From ab1de4a8212adac2380993ad36a91987af9b2116 Mon Sep 17 00:00:00 2001 From: Benjamin Uzelac Date: Wed, 9 Apr 2014 19:47:18 -0500 Subject: [PATCH 164/577] move comment to appropriate location --- Query/Builder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 68f0031df..13dc36c71 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1549,13 +1549,13 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) */ public function getPaginationCount() { + // Because some database engines may throw errors if we leave the ordering + // statements on the query, we will "back them up" and remove them from + // the query. Once we have the count we will put them back onto this. list($orders, $this->orders) = array($this->orders, null); $columns = $this->columns; - // Because some database engines may throw errors if we leave the ordering - // statements on the query, we will "back them up" and remove them from - // the query. Once we have the count we will put them back onto this. $total = $this->count(); $this->orders = $orders; From 82914123dd2b45f30fbf3aab53a8ad1bda573c7b Mon Sep 17 00:00:00 2001 From: Benjamin Uzelac Date: Wed, 9 Apr 2014 19:51:27 -0500 Subject: [PATCH 165/577] add multiple column count support for distinct pagination --- Query/Builder.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 13dc36c71..be4d97ec0 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1556,7 +1556,17 @@ public function getPaginationCount() $columns = $this->columns; - $total = $this->count(); + // We have to check if the value is "null" so that the count function does + // not attempt to count an invalid string. Checking the value is better + // here because the count function already has an optional parameter. + if ( is_null($columns)) + { + $total = $this->count(); + } + else + { + $total = $this->count($columns); + } $this->orders = $orders; @@ -1581,12 +1591,17 @@ public function exists() /** * Retrieve the "count" result of the query. * - * @param string $column + * @param string $columns * @return int */ - public function count($column = '*') + public function count($columns = '*') { - return (int) $this->aggregate(__FUNCTION__, array($column)); + if ( ! is_array($columns)) + { + $columns = array($columns); + } + + return (int) $this->aggregate(__FUNCTION__, $columns); } /** From f0b0f10d7fcce038f82d7f3f1e49d6d39f996ef0 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 9 Apr 2014 20:41:00 -0400 Subject: [PATCH 166/577] Model hydrate and hydrateRaw methods --- Eloquent/Model.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e0dcd2806..2309964fb 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -398,6 +398,56 @@ public function newFromBuilder($attributes = array()) return $instance; } + /** + * Create a collection of models that are existing. + * + * @param array $items + * @param string $connection + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function hydrate(array $items, $connection = null) + { + $instance = new static; + + $collection = $instance->newCollection(); + + foreach ($items as $item) + { + $model = $instance->newFromBuilder($item); + + if ( ! is_null($connection)) + { + $model->setConnection($connection); + } + + $collection->push($model); + } + + return $collection; + } + + /** + * Create a collection of models from a raw query. + * + * @param string $query + * @param array $bindings + * @param string $connection + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function hydrateRaw($query, $bindings = array(), $connection = null) + { + $instance = new static; + + if ( ! is_null($connection)) + { + $instance->setConnection($connection); + } + + $items = $instance->getConnection()->select($query, $bindings); + + return static::hydrate($items, $connection); + } + /** * Save a new model and return the instance. * From 0938f3814b0ac8d3f0a0c1f33169af071e2fb8be Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 09:07:08 -0500 Subject: [PATCH 167/577] cleaning up a few things. --- Eloquent/Model.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2309964fb..7d396a9f2 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -399,17 +399,15 @@ public function newFromBuilder($attributes = array()) } /** - * Create a collection of models that are existing. + * Create a collection of models from plain arrays. * - * @param array $items + * @param array $items * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ public static function hydrate(array $items, $connection = null) { - $instance = new static; - - $collection = $instance->newCollection(); + $collection = with($instance = new static)->newCollection(); foreach ($items as $item) { @@ -430,7 +428,7 @@ public static function hydrate(array $items, $connection = null) * Create a collection of models from a raw query. * * @param string $query - * @param array $bindings + * @param array $bindings * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ From 90c106790df091579c0b93759a637b298372b93b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 09:11:00 -0500 Subject: [PATCH 168/577] fixing tests. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7d396a9f2..36281cb3b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -405,7 +405,7 @@ public function newFromBuilder($attributes = array()) * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ - public static function hydrate(array $items, $connection = null) + public static function hydrate(array $items = array(), $connection = null) { $collection = with($instance = new static)->newCollection(); From 1ec0dd3de905c5f49cbb1d39a0b0c1c65316e6cc Mon Sep 17 00:00:00 2001 From: Benjamin Uzelac Date: Fri, 11 Apr 2014 09:45:53 -0500 Subject: [PATCH 169/577] fix spacing --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index be4d97ec0..fde0b3c3c 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1559,7 +1559,7 @@ public function getPaginationCount() // We have to check if the value is "null" so that the count function does // not attempt to count an invalid string. Checking the value is better // here because the count function already has an optional parameter. - if ( is_null($columns)) + if (is_null($columns)) { $total = $this->count(); } From 5d986ac5d27047f1d708517141e56e2950981dfe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 09:58:42 -0500 Subject: [PATCH 170/577] cleaning up some code. --- Connection.php | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Connection.php b/Connection.php index 12bdadea0..c0b014b35 100755 --- a/Connection.php +++ b/Connection.php @@ -455,10 +455,7 @@ public function beginTransaction() $this->pdo->beginTransaction(); } - if (isset($this->events)) - { - $this->events->fire('connection.beganTransaction', $this); - } + $this->fireConnectionEvent('beganTransaction'); } /** @@ -472,10 +469,7 @@ public function commit() --$this->transactions; - if (isset($this->events)) - { - $this->events->fire('connection.commited', $this); - } + $this->fireConnectionEvent('committed'); } /** @@ -496,10 +490,17 @@ public function rollBack() --$this->transactions; } - if (isset($this->events)) - { - $this->events->fire('connection.rollBacked', $this); - } + $this->fireConnectionEvent('rollingBack'); + } + + /** + * Get the number of active transactions. + * + * @return int + */ + public function transactionLevel() + { + return $this->transactions; } /** @@ -598,6 +599,20 @@ public function listen(Closure $callback) } } + /** + * Fire an event for this connection. + * + * @param string $event + * @return void + */ + protected function fireConnectionEvent($event) + { + if (isset($this->events)) + { + $this->events->fire('connection.'.$this->getName().'.'.$event, $this); + } + } + /** * Get the elapsed time since a given starting point. * @@ -893,16 +908,6 @@ public function setFetchMode($fetchMode) $this->fetchMode = $fetchMode; } - /** - * Get the number of active transactions. - * - * @return int - */ - public function getTransactions() - { - return $this->transactions; - } - /** * Get the connection query log. * From ce93ee7ea298071a7d094a10a2cf2f9e6562ecb8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 10:40:09 -0500 Subject: [PATCH 171/577] Lower case the array keys when doing aggregate. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 68f0031df..0b522ba66 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1653,7 +1653,7 @@ public function aggregate($function, $columns = array('*')) if (isset($results[0])) { - $result = (array) $results[0]; + $result = array_change_key_case((array) $results[0]); return $result['aggregate']; } From 2f41bf5a36ffe21a011cc2b15c3602e9869a2151 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 11:16:08 -0500 Subject: [PATCH 172/577] Fix nested relations with subset names. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index d7d888ff6..239e657ae 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -579,7 +579,7 @@ protected function isNested($name, $relation) { $dots = str_contains($name, '.'); - return $dots && starts_with($name, $relation) && $name != $relation; + return $dots && starts_with($name, $relation.'.') && $name != $relation; } /** From 5b19b1afa28f659da892cc070615b8eda050d666 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 11:16:42 -0500 Subject: [PATCH 173/577] Remove unnecessary check. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 239e657ae..ca4d57d82 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -579,7 +579,7 @@ protected function isNested($name, $relation) { $dots = str_contains($name, '.'); - return $dots && starts_with($name, $relation.'.') && $name != $relation; + return $dots && starts_with($name, $relation.'.'); } /** From 134b0263f7ad18c9d43248fa7d0b330d2e46454a Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 11 Apr 2014 14:11:18 -0400 Subject: [PATCH 174/577] Make Model::hydrate's first argument mandatory --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 36281cb3b..7d396a9f2 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -405,7 +405,7 @@ public function newFromBuilder($attributes = array()) * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ - public static function hydrate(array $items = array(), $connection = null) + public static function hydrate(array $items, $connection = null) { $collection = with($instance = new static)->newCollection(); From 93b72e2af892055bbb87ec6a60b6127cd61023dc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Apr 2014 14:13:26 -0500 Subject: [PATCH 175/577] Cleaning up some code. --- Eloquent/Model.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c3d07466b..04d49bb4b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2528,18 +2528,23 @@ public function syncOriginal() } /** - * Determine if the model is dirty or if a given attribute is dirty. + * Determine if the model or a given attribute has been modified. * * @param string|null $attribute * @return bool */ public function isDirty($attribute = null) { - $dirtyAttributes = $this->getDirty(); - - if (is_null($attribute) === false) return array_key_exists($attribute, $dirtyAttributes); + $dirty = $this->getDirty(); - return count($dirtyAttributes) > 0; + if (is_null($attribute)) + { + return count($dirty) > 0; + } + else + { + return array_key_exists($attribute, $dirty); + } } /** From fc219aa95a3e1e2061be8db8bea6fe679ddf5ff6 Mon Sep 17 00:00:00 2001 From: Rob Wells Date: Tue, 15 Apr 2014 14:30:50 +0100 Subject: [PATCH 176/577] Made getKeys return a unique array of keys. This was causing applications to crash if there was somehow thousands of keys, but where most the same. --- Eloquent/Relations/Relation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 8de641ae7..cb46bcd2f 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -171,11 +171,11 @@ public static function noConstraints(Closure $callback) */ protected function getKeys(array $models, $key = null) { - return array_values(array_map(function($value) use ($key) + return array_unique(array_values(array_map(function($value) use ($key) { return $key ? $value->getAttribute($key) : $value->getKey(); - }, $models)); + }, $models))); } /** From d899551e676c5d03af22faa2aa2b754606405c13 Mon Sep 17 00:00:00 2001 From: ipsq Date: Tue, 15 Apr 2014 21:56:29 +0200 Subject: [PATCH 177/577] Use Unix Socket or Host and port Referring to this (http://us3.php.net/manual/en/ref.pdo-mysql.connection.php) document explaining that unix socket should not be used together with Host and Port. --- Connectors/MySqlConnector.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index 8cddc069b..fb08028bb 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -55,17 +55,18 @@ protected function getDsn(array $config) // need to establish the PDO connections and return them back for use. extract($config); - $dsn = "mysql:host={$host};dbname={$database}"; - - if (isset($config['port'])) + $dsn = "mysql:dbname={$database}"; + + if (isset($config['unix_socket'])) { - $dsn .= ";port={$port}"; - } - - // Sometimes the developer may specify the specific UNIX socket that should - // be used. If that is the case we will add that option to the string we - // have created so that it gets utilized while the connection is made. - if (isset($config['unix_socket'])) + $dsn .= ";host={$host}"; + + if (isset($config['port'])) + { + $dsn .= ";port={$port}"; + } + } + else { $dsn .= ";unix_socket={$config['unix_socket']}"; } From da34c8eebd392ba51615c8ff2431986baba8f78a Mon Sep 17 00:00:00 2001 From: ipsq Date: Tue, 15 Apr 2014 21:56:59 +0200 Subject: [PATCH 178/577] Missed an ! Can happen sometimes. --- Connectors/MySqlConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index fb08028bb..e05d28e3b 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -57,7 +57,7 @@ protected function getDsn(array $config) $dsn = "mysql:dbname={$database}"; - if (isset($config['unix_socket'])) + if (!isset($config['unix_socket'])) { $dsn .= ";host={$host}"; From 5186f2ac59337518dc07f72b9298762f6ee00b8b Mon Sep 17 00:00:00 2001 From: ipsq Date: Tue, 15 Apr 2014 22:45:02 +0200 Subject: [PATCH 179/577] Decided to add the dbname at the end. Add exec use db name. Makes it more general. Everbody does it like that. Added it for Unix Sockets. --- Connectors/MySqlConnector.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index e05d28e3b..ff3c58bde 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -18,6 +18,13 @@ public function connect(array $config) $options = $this->getOptions($config); $connection = $this->createConnection($dsn, $config, $options); + + // We need to explicitly exec the 'use' mysql command in case the + // unix_socket option is used in the dsn. + if (isset($config['unix_socket'])) + { + $connection->exec("use {$config['database']};"); + } $collation = $config['collation']; @@ -55,11 +62,11 @@ protected function getDsn(array $config) // need to establish the PDO connections and return them back for use. extract($config); - $dsn = "mysql:dbname={$database}"; + $dsn = "mysql:"; if (!isset($config['unix_socket'])) { - $dsn .= ";host={$host}"; + $dsn .= "host={$host}"; if (isset($config['port'])) { @@ -68,8 +75,10 @@ protected function getDsn(array $config) } else { - $dsn .= ";unix_socket={$config['unix_socket']}"; + $dsn .= "unix_socket={$config['unix_socket']}"; } + + $dsn .= ";dbname={$database}"; return $dsn; } From 9a8c5e9a75b4852e2007653bc1569d82354f5887 Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Wed, 16 Apr 2014 01:49:36 +0100 Subject: [PATCH 180/577] Fixed typos --- Connection.php | 2 +- Connectors/SQLiteConnector.php | 2 +- Eloquent/Model.php | 6 +++--- Eloquent/Relations/BelongsToMany.php | 6 +++--- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/HasOneOrMany.php | 4 ++-- Eloquent/Relations/MorphTo.php | 2 +- Eloquent/Relations/Relation.php | 2 +- Migrations/Migrator.php | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Connection.php b/Connection.php index c0b014b35..cb6bde8fd 100755 --- a/Connection.php +++ b/Connection.php @@ -72,7 +72,7 @@ class Connection implements ConnectionInterface { protected $fetchMode = PDO::FETCH_ASSOC; /** - * The number of active transasctions. + * The number of active transactions. * * @var int */ diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index e73d78fb6..576d8193b 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -24,7 +24,7 @@ public function connect(array $config) $path = realpath($config['database']); - // Here we'll verify that the SQLite database exists before we gooing further + // Here we'll verify that the SQLite database exists before we going further // as the developer probably wants to know if the database exists and this // SQLite driver will not throw any exception if it does not by default. if ($path === false) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7d396a9f2..84131d09c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -685,7 +685,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat { // 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. + // of the time this will be what we desire to use for the relationships. if (is_null($relation)) { list(, $caller) = debug_backtrace(false); @@ -745,7 +745,7 @@ public function morphTo($name = null, $type = null, $id = null) ); } - // If we are not eager loading the relatinship, we will essentially treat this + // If we are not eager loading the relationship, 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 @@ -1337,7 +1337,7 @@ public function push() // To sync all of the relationships to the database, we will simply spin through // the relationships and save each model via this "push" method, which allows - // us to recurse into all of these nested relations for the model instance. + // us to recurs into all of these nested relations for the model instance. foreach ($this->relations as $models) { foreach (Collection::make($models) as $model) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 920a0ea03..1b55ba4fc 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -785,7 +785,7 @@ protected function createAttachRecord($id, $timed) } /** - * Set the creation and update timstamps on an attach record. + * Set the creation and update timestamps on an attach record. * * @param array $record * @param bool $exists @@ -965,7 +965,7 @@ public function getRelatedFreshUpdate() } /** - * Get the key for comparing against the pareny key in "has" query. + * Get the key for comparing against the parent key in "has" query. * * @return string */ @@ -995,7 +995,7 @@ public function getOtherKey() } /** - * Get the fully qualified parent key naem. + * Get the fully qualified parent key name. * * @return string */ diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 075803446..462ee7823 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -243,7 +243,7 @@ protected function getQualifiedParentKeyName() } /** - * Get the key for comparing against the pareny key in "has" query. + * Get the key for comparing against the parent key in "has" query. * * @return string */ diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 1605f02e0..c3b0ba790 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -240,7 +240,7 @@ public function update(array $attributes) } /** - * Get the key for comparing against the pareny key in "has" query. + * Get the key for comparing against the parent key in "has" query. * * @return string */ @@ -282,7 +282,7 @@ public function getParentKey() } /** - * Get the fully qualified parent key naem. + * Get the fully qualified parent key name. * * @return string */ diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index cab45a124..ad80fb9ab 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -58,7 +58,7 @@ public function addEagerConstraints(array $models) } /** - * Buiild a dictionary with the models. + * Build a dictionary with the models. * * @param \Illuminate\Database\Eloquent\Models $models * @return void diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 2c1692252..8b0ce0268 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -219,7 +219,7 @@ public function getParent() } /** - * Get the fully qualified parent key naem. + * Get the fully qualified parent key name. * * @return string */ diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 548949b2f..cc3024670 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -72,7 +72,7 @@ public function run($path, $pretend = false) // Once we grab all of the migration files for the path, we will compare them // against the migrations that have already been run for this package then - // run all of the oustanding migrations against the database connection. + // run all of the outstanding migrations against the database connection. $ran = $this->repository->getRan(); $migrations = array_diff($files, $ran); From 652c75726c27a0f33c9b574457e408d936d6918a Mon Sep 17 00:00:00 2001 From: Mohammad Gufran Date: Wed, 16 Apr 2014 23:49:09 +0530 Subject: [PATCH 181/577] destructive migration tasks iin production will prompt for confirmation --- Console/Migrations/BaseCommand.php | 15 +++++++++++++++ Console/Migrations/MigrateCommand.php | 10 +++++++++- Console/Migrations/RefreshCommand.php | 11 +++++++++-- Console/Migrations/ResetCommand.php | 11 +++++++++-- Console/Migrations/RollbackCommand.php | 11 +++++++++-- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 7dfef5770..9606f1229 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -46,4 +46,19 @@ protected function getMigrationPath() return $this->laravel['path'].'/database/migrations'; } + /** + * Confirm before proceeding with the action + * + * @return bool + */ + public function confirmToProceed() + { + if($this->getLaravel()->environment() == 'production') + { + $this->output->writeln('Application is in Production'); + return $this->confirm('Do you really wish to continue ?'); + } + + return true; + } } diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index b9c95330d..e904e48be 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -53,7 +53,15 @@ public function __construct(Migrator $migrator, $packagePath) */ public function fire() { - $this->prepareDatabase(); + $proceed = $this->confirmToProceed(); + + if( ! $proceed ) + { + $this->output->writeln('Did not migrated'); + return; + } + + $this->prepareDatabase(); // The pretend option can be used for "simulating" the migration and grabbing // the SQL queries that would fire if the migration were to be run against diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index e3559313f..ed5fe834c 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -1,9 +1,8 @@ confirmToProceed(); + + if( ! $proceed ) + { + $this->output->writeln('Did not refreshed migrations'); + return; + } + $database = $this->input->getOption('database'); $this->call('migrate:reset', array('--database' => $database)); diff --git a/Console/Migrations/ResetCommand.php b/Console/Migrations/ResetCommand.php index 223ee40ce..7b89b8951 100755 --- a/Console/Migrations/ResetCommand.php +++ b/Console/Migrations/ResetCommand.php @@ -1,10 +1,9 @@ confirmToProceed(); + + if( ! $proceed ) + { + $this->output->writeln('Did not Reset the migrations'); + return; + } + $this->migrator->setConnection($this->input->getOption('database')); $pretend = $this->input->getOption('pretend'); diff --git a/Console/Migrations/RollbackCommand.php b/Console/Migrations/RollbackCommand.php index 8e854880b..8dec6a250 100755 --- a/Console/Migrations/RollbackCommand.php +++ b/Console/Migrations/RollbackCommand.php @@ -1,10 +1,9 @@ confirmToProceed(); + + if( ! $proceed ) + { + $this->output->writeln('Did not Rollback migrations'); + return; + } + $this->migrator->setConnection($this->input->getOption('database')); $pretend = $this->input->getOption('pretend'); From a104b1ee5eac5a54613b09b3ffe26713f663537b Mon Sep 17 00:00:00 2001 From: Mohammad Gufran Date: Thu, 17 Apr 2014 00:51:47 +0530 Subject: [PATCH 182/577] fixed formatting and grammer --- Console/Migrations/BaseCommand.php | 34 +++++++++++++++----------- Console/Migrations/MigrateCommand.php | 8 +----- Console/Migrations/RefreshCommand.php | 8 +----- Console/Migrations/ResetCommand.php | 8 +----- Console/Migrations/RollbackCommand.php | 8 +----- 5 files changed, 24 insertions(+), 42 deletions(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 9606f1229..613197809 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -46,19 +46,25 @@ protected function getMigrationPath() return $this->laravel['path'].'/database/migrations'; } - /** - * Confirm before proceeding with the action - * - * @return bool - */ - public function confirmToProceed() - { - if($this->getLaravel()->environment() == 'production') - { - $this->output->writeln('Application is in Production'); - return $this->confirm('Do you really wish to continue ?'); - } + /** + * Confirm before proceeding with the action + * + * @return bool + */ + public function confirmToProceed() + { + if($this->getLaravel()->environment() == 'production') + { + $this->output->writeln('Application is in Production'); + $confirmed = $this->confirm('Do you really wish to continue ?'); + + if( ! $confirmed) + { + $this->output->writeln('Migration Operation Was Cancelled'); + return false; + } + } - return true; - } + return true; + } } diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index e904e48be..7696bb10a 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -53,13 +53,7 @@ public function __construct(Migrator $migrator, $packagePath) */ public function fire() { - $proceed = $this->confirmToProceed(); - - if( ! $proceed ) - { - $this->output->writeln('Did not migrated'); - return; - } + if( ! $this->confirmToProceed()) return; $this->prepareDatabase(); diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index ed5fe834c..80953a839 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -25,13 +25,7 @@ class RefreshCommand extends BaseCommand { */ public function fire() { - $proceed = $this->confirmToProceed(); - - if( ! $proceed ) - { - $this->output->writeln('Did not refreshed migrations'); - return; - } + if( ! $this->confirmToProceed()) return; $database = $this->input->getOption('database'); diff --git a/Console/Migrations/ResetCommand.php b/Console/Migrations/ResetCommand.php index 7b89b8951..2fa022914 100755 --- a/Console/Migrations/ResetCommand.php +++ b/Console/Migrations/ResetCommand.php @@ -46,13 +46,7 @@ public function __construct(Migrator $migrator) */ public function fire() { - $proceed = $this->confirmToProceed(); - - if( ! $proceed ) - { - $this->output->writeln('Did not Reset the migrations'); - return; - } + if( ! $this->confirmToProceed()) return; $this->migrator->setConnection($this->input->getOption('database')); diff --git a/Console/Migrations/RollbackCommand.php b/Console/Migrations/RollbackCommand.php index 8dec6a250..92a74f0b2 100755 --- a/Console/Migrations/RollbackCommand.php +++ b/Console/Migrations/RollbackCommand.php @@ -46,13 +46,7 @@ public function __construct(Migrator $migrator) */ public function fire() { - $proceed = $this->confirmToProceed(); - - if( ! $proceed ) - { - $this->output->writeln('Did not Rollback migrations'); - return; - } + if( ! $this->confirmToProceed()) return; $this->migrator->setConnection($this->input->getOption('database')); From ddffb01cd7ff6ddb3e908767f7c69aab96c26520 Mon Sep 17 00:00:00 2001 From: Mohammad Gufran Date: Thu, 17 Apr 2014 00:53:43 +0530 Subject: [PATCH 183/577] fixed indentation width --- Console/Migrations/MigrateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 7696bb10a..3c087fbb2 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -55,7 +55,7 @@ public function fire() { if( ! $this->confirmToProceed()) return; - $this->prepareDatabase(); + $this->prepareDatabase(); // The pretend option can be used for "simulating" the migration and grabbing // the SQL queries that would fire if the migration were to be run against From 87df0d15dc55d558b6106b5b499bd293085480ba Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 09:08:54 -0500 Subject: [PATCH 184/577] Move confirmation to a trait. Added force flags to relevant operations. --- Console/Migrations/BaseCommand.php | 21 --------------------- Console/Migrations/MigrateCommand.php | 7 ++++++- Console/Migrations/RefreshCommand.php | 10 ++++++++-- Console/Migrations/ResetCommand.php | 10 ++++++++-- Console/Migrations/RollbackCommand.php | 10 ++++++++-- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 613197809..7dfef5770 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -46,25 +46,4 @@ protected function getMigrationPath() return $this->laravel['path'].'/database/migrations'; } - /** - * Confirm before proceeding with the action - * - * @return bool - */ - public function confirmToProceed() - { - if($this->getLaravel()->environment() == 'production') - { - $this->output->writeln('Application is in Production'); - $confirmed = $this->confirm('Do you really wish to continue ?'); - - if( ! $confirmed) - { - $this->output->writeln('Migration Operation Was Cancelled'); - return false; - } - } - - return true; - } } diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 3c087fbb2..0ce464044 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -1,10 +1,13 @@ confirmToProceed()) return; + if ( ! $this->confirmToProceed()) return; $this->prepareDatabase(); @@ -112,6 +115,8 @@ protected function getOptions() array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null), array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null), diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 80953a839..09ab0003f 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -1,8 +1,12 @@ confirmToProceed()) return; + if ( ! $this->confirmToProceed()) return; $database = $this->input->getOption('database'); @@ -75,6 +79,8 @@ protected function getOptions() return array( array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'), diff --git a/Console/Migrations/ResetCommand.php b/Console/Migrations/ResetCommand.php index 2fa022914..f81fa907d 100755 --- a/Console/Migrations/ResetCommand.php +++ b/Console/Migrations/ResetCommand.php @@ -1,9 +1,13 @@ confirmToProceed()) return; + if ( ! $this->confirmToProceed()) return; $this->migrator->setConnection($this->input->getOption('database')); @@ -78,6 +82,8 @@ protected function getOptions() return array( array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), ); } diff --git a/Console/Migrations/RollbackCommand.php b/Console/Migrations/RollbackCommand.php index 92a74f0b2..c11198f6f 100755 --- a/Console/Migrations/RollbackCommand.php +++ b/Console/Migrations/RollbackCommand.php @@ -1,9 +1,13 @@ confirmToProceed()) return; + if ( ! $this->confirmToProceed()) return; $this->migrator->setConnection($this->input->getOption('database')); @@ -73,6 +77,8 @@ protected function getOptions() return array( array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), ); } From 5846316227f54c787988f14785f41e8122ae7579 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 10:17:37 -0500 Subject: [PATCH 185/577] Fix some comments. --- Connectors/SQLiteConnector.php | 2 +- Eloquent/Model.php | 4 ++-- Migrations/Migrator.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index 576d8193b..596ef28b3 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -24,7 +24,7 @@ public function connect(array $config) $path = realpath($config['database']); - // Here we'll verify that the SQLite database exists before we going further + // Here we'll verify that the SQLite database exists before going any further // as the developer probably wants to know if the database exists and this // SQLite driver will not throw any exception if it does not by default. if ($path === false) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 84131d09c..d13fa6005 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -745,7 +745,7 @@ public function morphTo($name = null, $type = null, $id = null) ); } - // If we are not eager loading the relationship, we will essentially treat this + // If we are not eager loading the relationship 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 @@ -1337,7 +1337,7 @@ public function push() // To sync all of the relationships to the database, we will simply spin through // the relationships and save each model via this "push" method, which allows - // us to recurs into all of these nested relations for the model instance. + // us to recurs into all of these nested relations for this model instance. foreach ($this->relations as $models) { foreach (Collection::make($models) as $model) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index cc3024670..3a1ecb525 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -72,7 +72,7 @@ public function run($path, $pretend = false) // Once we grab all of the migration files for the path, we will compare them // against the migrations that have already been run for this package then - // run all of the outstanding migrations against the database connection. + // run each of the outstanding migrations against a database connection. $ran = $this->repository->getRan(); $migrations = array_diff($files, $ran); From 9e6f671240472dabb65e7bc879b87efeed1114aa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 10:44:37 -0500 Subject: [PATCH 186/577] Return 0 from sum if result is null. --- Query/Builder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 0b522ba66..982899b6b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1619,7 +1619,9 @@ public function max($column) */ public function sum($column) { - return $this->aggregate(__FUNCTION__, array($column)); + $result = $this->aggregate(__FUNCTION__, array($column)); + + return $result ?: 0; } /** From 54b459fb4c7a52b69b80df857759a80c64633011 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 11:48:01 -0500 Subject: [PATCH 187/577] Cleaning up code organization. --- Connectors/MySqlConnector.php | 55 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index ff3c58bde..9ddf18b48 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -12,15 +12,13 @@ public function connect(array $config) { $dsn = $this->getDsn($config); + $options = $this->getOptions($config); + // We need to grab the PDO options that should be used while making the brand // new connection instance. The PDO options control various aspects of the // connection's behavior, and some might be specified by the developers. - $options = $this->getOptions($config); - $connection = $this->createConnection($dsn, $config, $options); - - // We need to explicitly exec the 'use' mysql command in case the - // unix_socket option is used in the dsn. + if (isset($config['unix_socket'])) { $connection->exec("use {$config['database']};"); @@ -57,30 +55,35 @@ public function connect(array $config) */ protected function getDsn(array $config) { - // First we will create the basic DSN setup as well as the port if it is in - // in the configuration options. This will give us the basic DSN we will - // need to establish the PDO connections and return them back for use. + return isset($config['unix_socket']) ? $this->getSocketDsn($config) : $this->getHostDsn($config); + } + + /** + * Get the DSN string for a socket configuration. + * + * @param array $config + * @return string + */ + protected function getSocketDsn(array $config) + { extract($config); - $dsn = "mysql:"; - - if (!isset($config['unix_socket'])) - { - $dsn .= "host={$host}"; - - if (isset($config['port'])) - { - $dsn .= ";port={$port}"; - } - } - else - { - $dsn .= "unix_socket={$config['unix_socket']}"; - } - - $dsn .= ";dbname={$database}"; + return "mysql:unix_socket={$config['unix_socket']};dbname={$database}"; + } + + /** + * Get the DSN string for a host / port configuration. + * + * @param array $config + * @return string + */ + protected function getHostDsn(array $config) + { + extract($config); - return $dsn; + return isset($config['port']) + ? "mysql:host={$host};port={$port};dbname={$database}" + : "mysql:host={$host};dbname={$database}"; } } From 536a4d888e0a6f486e3aa76676f97d7ff21ba248 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 14:57:02 -0500 Subject: [PATCH 188/577] Just cleaning a few things. --- Query/Builder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 9fe09fbf5..22aa3d47a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -35,11 +35,11 @@ class Builder { * @var array */ protected $bindings = array( - 'select' => array(), - 'join' => array(), - 'where' => array(), - 'having' => array(), - 'order' => array(), + 'select' => [], + 'join' => [], + 'where' => [], + 'having' => [], + 'order' => [], ); /** @@ -1908,7 +1908,7 @@ public function setBindings(array $bindings, $type = 'where') { if ( ! array_key_exists($type, $this->bindings)) { - throw new \InvalidArgumentException("Invalid binding type: $type"); + throw new \InvalidArgumentException("Invalid binding type: {$type}."); } $this->bindings[$type] = $bindings; @@ -1927,7 +1927,7 @@ public function addBinding($value, $type = 'where') { if ( ! array_key_exists($type, $this->bindings)) { - throw new \InvalidArgumentException("Invalid binding type: $type"); + throw new \InvalidArgumentException("Invalid binding type: {$type}."); } if (is_array($value)) From 11b89bdb61eb202bf264b3a7fb0f960689c9cb26 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 16:13:41 -0500 Subject: [PATCH 189/577] Clean up code. Method extraction. --- Eloquent/Model.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2a41437ec..a735aeaee 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2649,17 +2649,31 @@ public function getDirty() { $dirty[$key] = $value; } - else if ($value !== $this->original[$key]) { - // two equivilent numerical fields shouldn't match as 'dirty', e.g. 1 and "1" - if (!is_numeric($value) || !is_numeric($this->original[$key]) || strcmp((string) $value, (string) $this->original[$key]) != 0) { - $dirty[$key] = $value; - } + elseif ($value !== $this->original[$key] && + ! $this->originalIsNumericallyEquivalent($key)) + { + $dirty[$key] = $value; } } return $dirty; } + /** + * Deteremine if the new and old values for a given key are numerically equivalent. + * + * @param string $key + * @return bool + */ + protected function originalIsNumericallyEquivalent($key) + { + $current = $this->attributes[$key]; + + $original = $this->original[$key]; + + return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; + } + /** * Get all the loaded relations for the instance. * From 5d06fdd7aafe7d375f6f975611d7c99f58cb86bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Apr 2014 16:36:09 -0500 Subject: [PATCH 190/577] cleaning up some code. --- Query/Builder.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 435fb4002..80906e2c2 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -932,13 +932,14 @@ public function groupBy() * @param string $column * @param string $operator * @param string $value + * @param string $boolean * @return \Illuminate\Database\Query\Builder|static */ - public function having($column, $operator = null, $value = null,$boolean = 'and') + public function having($column, $operator = null, $value = null, $boolean = 'and') { $type = 'basic'; - $this->havings[] = compact('type', 'column', 'operator', 'value','boolean'); + $this->havings[] = compact('type', 'column', 'operator', 'value', 'boolean'); $this->addBinding($value, 'having'); @@ -946,17 +947,17 @@ public function having($column, $operator = null, $value = null,$boolean = 'and' } /** - * Add an "or having" clause to the query. - * - * @param string $column - * @param string $operator - * @param mixed $value - * @return \Illuminate\Database\Query\Builder|static - */ + * Add a "or having" clause to the query. + * + * @param string $column + * @param string $operator + * @param string $value + * @return \Illuminate\Database\Query\Builder|static + */ public function orHaving($column, $operator = null, $value = null) { return $this->having($column, $operator, $value, 'or'); - } + } /** * Add a raw having clause to the query. From 0d797630fa415d319b153af08e1b74d365938d7c Mon Sep 17 00:00:00 2001 From: Tom Rochette Date: Fri, 18 Apr 2014 19:08:33 -0400 Subject: [PATCH 191/577] Updated the return values (comments/docs) of a couple of methods. --- Eloquent/Relations/BelongsTo.php | 2 +- Eloquent/Relations/BelongsToMany.php | 4 ++-- Eloquent/Relations/HasMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/HasOne.php | 2 +- Eloquent/Relations/Relation.php | 2 +- Migrations/MigrationCreator.php | 2 +- Seeder.php | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Eloquent/Relations/BelongsTo.php b/Eloquent/Relations/BelongsTo.php index f1179a99c..ec78aebac 100755 --- a/Eloquent/Relations/BelongsTo.php +++ b/Eloquent/Relations/BelongsTo.php @@ -144,7 +144,7 @@ protected function getEagerModelKeys(array $models) * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 1b55ba4fc..bae75cec3 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -375,7 +375,7 @@ public function addEagerConstraints(array $models) * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { @@ -700,7 +700,7 @@ public function attach($id, array $attributes = array(), $touch = true) * Create an array of records to insert into the pivot table. * * @param array $ids - * @return void + * @return array */ protected function createAttachRecords($ids, array $attributes) { diff --git a/Eloquent/Relations/HasMany.php b/Eloquent/Relations/HasMany.php index 103f4892b..159a65820 100755 --- a/Eloquent/Relations/HasMany.php +++ b/Eloquent/Relations/HasMany.php @@ -19,7 +19,7 @@ public function getResults() * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 462ee7823..013df2e2f 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -116,7 +116,7 @@ public function addEagerConstraints(array $models) * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { diff --git a/Eloquent/Relations/HasOne.php b/Eloquent/Relations/HasOne.php index e4fa1517e..fd0f9a022 100755 --- a/Eloquent/Relations/HasOne.php +++ b/Eloquent/Relations/HasOne.php @@ -19,7 +19,7 @@ public function getResults() * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 8b0ce0268..c7de40fdc 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -72,7 +72,7 @@ abstract public function addEagerConstraints(array $models); * * @param array $models * @param string $relation - * @return void + * @return array */ abstract public function initRelation(array $models, $relation); diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index 58761963a..1b6460e89 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -59,7 +59,7 @@ public function create($name, $path, $table = null, $create = false) * Get the migration stub file. * * @param string $table - * @return void + * @return string */ protected function getStub($table, $create) { diff --git a/Seeder.php b/Seeder.php index cb0d939ff..547cfb969 100755 --- a/Seeder.php +++ b/Seeder.php @@ -73,7 +73,7 @@ protected function resolve($class) * Set the IoC container instance. * * @param \Illuminate\Container\Container $container - * @return void + * @return \Illuminate\Database\Seeder */ public function setContainer(Container $container) { @@ -86,7 +86,7 @@ public function setContainer(Container $container) * Set the console command instance. * * @param \Illuminate\Console\Command $command - * @return void + * @return \Illuminate\Database\Seeder */ public function setCommand(Command $command) { From eb31e7a8684fae573179b0647f9b76183851c39c Mon Sep 17 00:00:00 2001 From: Tom Rochette Date: Fri, 18 Apr 2014 19:33:38 -0400 Subject: [PATCH 192/577] Fixed various typos and some additional phpdoc. --- Eloquent/Model.php | 4 ++-- Eloquent/Relations/MorphMany.php | 2 +- Eloquent/Relations/MorphOne.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a735aeaee..4c58785e6 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2660,7 +2660,7 @@ public function getDirty() } /** - * Deteremine if the new and old values for a given key are numerically equivalent. + * Determine if the new and old values for a given key are numerically equivalent. * * @param string $key * @return bool @@ -2907,7 +2907,7 @@ public function offsetUnset($offset) * Determine if an attribute exists on the model. * * @param string $key - * @return void + * @return bool */ public function __isset($key) { diff --git a/Eloquent/Relations/MorphMany.php b/Eloquent/Relations/MorphMany.php index 85eb70a03..1abdf3797 100755 --- a/Eloquent/Relations/MorphMany.php +++ b/Eloquent/Relations/MorphMany.php @@ -19,7 +19,7 @@ public function getResults() * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { diff --git a/Eloquent/Relations/MorphOne.php b/Eloquent/Relations/MorphOne.php index dad79252c..fdebc24ee 100755 --- a/Eloquent/Relations/MorphOne.php +++ b/Eloquent/Relations/MorphOne.php @@ -19,7 +19,7 @@ public function getResults() * * @param array $models * @param string $relation - * @return void + * @return array */ public function initRelation(array $models, $relation) { From 8f750a0215b280d86b5aadf162618fc6907bda78 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 19 Apr 2014 15:21:02 +0200 Subject: [PATCH 193/577] Add subselect to query builder --- Query/Builder.php | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 80906e2c2..cf298b002 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -206,11 +206,58 @@ public function select($columns = array('*')) * Add a new "raw" select expression to the query. * * @param string $expression + * @param array $bindings + * @return \Illuminate\Database\Query\Builder|static + */ + public function selectRaw($expression, array $bindings = array()) + { + $this->addSelect(new Expression($expression)); + + if ($bindings) + { + $this->addBinding($bindings, 'select'); + } + + return $this; + } + + /** + * Add a subselect expression to the query. + * + * @param \Closure|\Illuminate\Database\Query\Builder|string $query + * @param string $as * @return \Illuminate\Database\Query\Builder|static */ - public function selectRaw($expression) + public function selectSub($query, $as) { - return $this->select(new Expression($expression)); + if ($query instanceof Closure) + { + $callback = $query; + $query = $this->newQuery(); + $callback($query); + } + + if ($query instanceof Builder) + { + $bindings = $query->getBindings(); + $query = $query->toSql(); + } + elseif (is_string($query)) + { + $bindings = []; + } + else + { + $type = is_object($query) ? get_class($query) : gettype($query); + $message = "Argument #1 passed to selectSub must be an SQL string, query builder or closure, {$type} given"; + throw new \InvalidArgumentException($message); + } + + $as = $this->grammar->wrap($as); + + $query = '(' . $query . ') as ' . $as; + + return $this->selectRaw($query, $bindings); } /** From 38f92635d088b9d531dab5c3425a1f755b510152 Mon Sep 17 00:00:00 2001 From: Paulo Freitas Date: Sat, 19 Apr 2014 13:36:35 -0300 Subject: [PATCH 194/577] Fixed a few typos. --- Console/Migrations/RefreshCommand.php | 2 +- DatabaseManager.php | 2 +- Eloquent/Builder.php | 2 +- Eloquent/Model.php | 2 +- Eloquent/Relations/Relation.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index e3559313f..3968e4688 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -32,7 +32,7 @@ public function fire() // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute - // them in succession. We'll also see if we need to res-eed the database. + // them in succession. We'll also see if we need to reseed the database. $this->call('migrate', array('--database' => $database)); if ($this->needsSeeding()) diff --git a/DatabaseManager.php b/DatabaseManager.php index a8a7b3665..01ed3f627 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -153,7 +153,7 @@ protected function prepare(Connection $connection) }); // We will setup a Closure to resolve the paginator instance on the connection - // since the Paginator isn't sued on every request and needs quite a few of + // since the Paginator isn't used on every request and needs quite a few of // our dependencies. It'll be more efficient to lazily resolve instances. $connection->setPaginator(function() use ($app) { diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index ca4d57d82..576d10da4 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -523,7 +523,7 @@ public function getRelation($relation) { $me = $this; - // We want to run a relationship query without any constrains so that we will + // We want to run a relationship query without any constraints so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $query = Relation::noConstraints(function() use ($me, $relation) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 4c58785e6..bf66d8913 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1922,7 +1922,7 @@ public function getPerPage() } /** - * Set the number of models ot return per page. + * Set the number of models to return per page. * * @param int $perPage * @return void diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index c7de40fdc..9739dddf9 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -153,7 +153,7 @@ public function getRelationCountQuery(Builder $query, Builder $parent) } /** - * Run a callback with constrains disabled on the relation. + * Run a callback with constraints disabled on the relation. * * @param \Closure $callback * @return mixed From 213428d13f12ae426a14e3c178438c7db60d4f0e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 19 Apr 2014 13:01:24 -0500 Subject: [PATCH 195/577] Add hyphen. --- Console/Migrations/RefreshCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 3968e4688..f627f84f6 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -32,7 +32,7 @@ public function fire() // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute - // them in succession. We'll also see if we need to reseed the database. + // them in succession. We'll also see if we need to re-seed the database. $this->call('migrate', array('--database' => $database)); if ($this->needsSeeding()) From e52e79aa77ca8e6793aa5e5cc5791631296ad021 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 19 Apr 2014 13:02:02 -0500 Subject: [PATCH 196/577] Shorten line. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 576d10da4..e5490e792 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -523,7 +523,7 @@ public function getRelation($relation) { $me = $this; - // We want to run a relationship query without any constraints so that we will + // We want to do a relationship query without any constraints so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $query = Relation::noConstraints(function() use ($me, $relation) From 7aee047e47d7042e84a8b7ec44351f8300550598 Mon Sep 17 00:00:00 2001 From: Paulo Freitas Date: Sat, 19 Apr 2014 15:23:29 -0300 Subject: [PATCH 197/577] Fixed a few more typos. --- Eloquent/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7bb6bf455..06a698212 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -316,7 +316,7 @@ public static function addGlobalScope(ScopeInterface $scope) } /** - * Deteremine if a model has a global scope. + * Determine if a model has a global scope. * * @param \Illuminate\Database\Eloquent\ScopeInterface $scope * @return bool @@ -1669,7 +1669,7 @@ public function newQuery() } /** - * Get a new quer instance without a given scope. + * Get a new query instance without a given scope. * * @param \Illuminate\Database\Eloquent\ScopeInterface $scope * @return \Illuminate\Database\Eloquent\Builder @@ -1708,7 +1708,7 @@ public function applyGlobalScopes($builder) } /** - * Remove all of the global scopes from an Elouqent builder. + * Remove all of the global scopes from an Eloquent builder. * * @param \Illuminate\Database\Eloquent\Builder $builder * @return void From 107507fbc131c7d30d971f90dfe3e6c63f69b854 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 21 Apr 2014 20:50:33 +0100 Subject: [PATCH 198/577] Improvements --- Capsule/Manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 639989234..812dd1cb4 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -24,10 +24,10 @@ class Manager { * @var \Illuminate\Database\DatabaseManager */ protected $manager; - + /** * The container instance. - * + * * @var \Illuminate\Container\Container */ protected $container; From d802aa9c08aa7f46191bff965492992e6f21700d Mon Sep 17 00:00:00 2001 From: Jake Shelby Date: Thu, 24 Apr 2014 11:48:14 -0600 Subject: [PATCH 199/577] Stashing limit/offset query values before performing total pagination count Some database engines return zero, when using the count aggregate on a query with limit and offset. Just followed the same pattern for stashing the 'orders' clause before performing a count on the query, and adding back to the query when done. --- Query/Builder.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 982899b6b..6ae0ac6b6 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1550,15 +1550,20 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) public function getPaginationCount() { list($orders, $this->orders) = array($this->orders, null); + list($offset, $this->offset) = array($this->offset, null); + list($limit, $this->limit) = array($this->limit, null); $columns = $this->columns; - // Because some database engines may throw errors if we leave the ordering - // statements on the query, we will "back them up" and remove them from - // the query. Once we have the count we will put them back onto this. + // Because some database engines may throw errors, or return incorrect + // results, if we leave the ordering, limit, and/or offset statements on + // the query, we will "back them up" and remove them from the query. + // Once we have the count we will put them back onto this. $total = $this->count(); $this->orders = $orders; + $this->offset = $offset; + $this->limit = $limit; // Once the query is run we need to put the old select columns back on the // instance so that the select query will run properly. Otherwise, they From 4dd3d83f3fa04109b692a69273676adbde4ab69b Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Tue, 22 Apr 2014 14:51:32 +0100 Subject: [PATCH 200/577] Pivot updates recorded only if something updated --- Eloquent/Relations/BelongsToMany.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index bae75cec3..4db712b00 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -649,9 +649,10 @@ protected function attachNew(array $records, array $current, $touch = true) } elseif (count($attributes) > 0) { - $this->updateExistingPivot($id, $attributes, $touch); - - $changes['updated'][] = (int) $id; + if ($this->updateExistingPivot($id, $attributes, $touch)) + { + $changes['updated'][] = (int) $id; + } } } return $changes; @@ -672,9 +673,11 @@ public function updateExistingPivot($id, array $attributes, $touch) $attributes = $this->setTimestampsOnAttach($attributes, true); } - $this->newPivotStatementForId($id)->update($attributes); + $updated = $this->newPivotStatementForId($id)->update($attributes); if ($touch) $this->touchIfTouching(); + + return $updated; } /** From 74708261091dc2918b68d1df17849dd1943ac2c1 Mon Sep 17 00:00:00 2001 From: Jarek Tkaczyk Date: Fri, 25 Apr 2014 13:07:01 +0200 Subject: [PATCH 201/577] Fix associate on MorphTo --- Eloquent/Relations/MorphTo.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ad80fb9ab..bf0bceeb8 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -178,4 +178,19 @@ public function getDictionary() return $this->dictionary; } + /** + * Associate the model instance to the given parent. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function associate(Model $model) + { + $this->parent->setAttribute($this->foreignKey, $model->getKey()); + + $this->parent->setAttribute($this->morphType, get_class($model)); + + return $this->parent->setRelation($this->relation, $model); + } + } From 73acc4e8c96da6fab0d110c8fcfbe1734181f330 Mon Sep 17 00:00:00 2001 From: Andrei Canta Date: Fri, 25 Apr 2014 12:54:42 +0300 Subject: [PATCH 202/577] Add morphClass property to allow polymorphic relations on extended models --- Eloquent/Model.php | 17 +++++++++++++++++ Eloquent/Relations/MorphOneOrMany.php | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index bf66d8913..c45bd025d 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -205,6 +205,13 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ protected static $mutatorCache = array(); + /** + * The class name to be used in polymorphic relations + * + * @var string + */ + protected $morphClass; + /** * The many to many relationship methods. * @@ -1810,6 +1817,16 @@ public function newPivot(Model $parent, array $attributes, $table, $exists) return new Pivot($parent, $attributes, $table, $exists); } + /** + * Get the class name for polymorphic relations. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass ?: get_class($this); + } + /** * Get the table associated with the model. * diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index c020f1b86..a9c28bde4 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -27,13 +27,14 @@ abstract class MorphOneOrMany extends HasOneOrMany { * @param string $type * @param string $id * @param string $localKey + * @param string $morphClass * @return void */ public function __construct(Builder $query, Model $parent, $type, $id, $localKey) { $this->morphType = $type; - $this->morphClass = get_class($parent); + $this->morphClass = $parent->getMorphClass(); parent::__construct($query, $parent, $id, $localKey); } From fb201bf470337d52af354ef857cf5735307d1001 Mon Sep 17 00:00:00 2001 From: Shawn Welch Date: Wed, 30 Apr 2014 14:08:12 -0400 Subject: [PATCH 203/577] Added support for RLIKE, REGEXP and NOT REGEXP operators --- Query/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Query/Builder.php b/Query/Builder.php index 80906e2c2..7b63f62e4 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -170,6 +170,7 @@ class Builder { '=', '<', '>', '<=', '>=', '<>', '!=', 'like', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', + 'rlike', 'regexp', 'not regexp', ); /** From ecfa8f21227e59371f00421abe54842029f8fe9c Mon Sep 17 00:00:00 2001 From: skovacs1 Date: Wed, 30 Apr 2014 12:24:07 -0700 Subject: [PATCH 204/577] Fix many to many polymorphic pivot updates `$morphType ` set by `setMorphType` is being included in queries from x->pivot->save() and the like. As the object is being added as a public data member on an object with an empty original, it is treated as an attribute and added as a column to the queries. As this column doesn't exist, the query will be erroneous. https://github.com/laravel/framework/issues/3693 --- Eloquent/Relations/MorphPivot.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index 7daa0fb61..b0385903a 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -4,6 +4,13 @@ class MorphPivot extends Pivot { + /** + * The type of the polymorphic relation. + * + * @var string + */ + protected $morphType; + /** * Set the keys for a save update query. * From 2c1887f067c5e9f1bd522e7cd130a17fd43c5f99 Mon Sep 17 00:00:00 2001 From: kapil verma Date: Fri, 2 May 2014 01:33:08 +0530 Subject: [PATCH 205/577] `attributesToArray` can handle instances of `ArrayableInterface` basically some mutators can return instances of `ArrayableInterface`, and this case is not handled by `attributesToArray`, so put that condition in there --- Eloquent/Model.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index bf66d8913..828eaf9ee 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2187,9 +2187,11 @@ public function attributesToArray() { if ( ! array_key_exists($key, $attributes)) continue; - $attributes[$key] = $this->mutateAttribute( + $value = $this->mutateAttribute( $key, $attributes[$key] ); + + $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() () : $value; } // Here we will grab all of the appended, calculated attributes to this model @@ -2197,7 +2199,9 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->appends as $key) { - $attributes[$key] = $this->mutateAttribute($key, null); + $value = $this->mutateAttribute($key, null); + + $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() () : $value; } return $attributes; From a513b487573cec25e6916c8ef3180db7efdd4ace Mon Sep 17 00:00:00 2001 From: kapil verma Date: Fri, 2 May 2014 04:01:24 +0530 Subject: [PATCH 206/577] removed syntax error --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 828eaf9ee..05ec4aaa2 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2191,7 +2191,7 @@ public function attributesToArray() $key, $attributes[$key] ); - $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() () : $value; + $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() : $value; } // Here we will grab all of the appended, calculated attributes to this model @@ -2201,7 +2201,7 @@ public function attributesToArray() { $value = $this->mutateAttribute($key, null); - $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() () : $value; + $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() : $value; } return $attributes; From a10eeb3dcccd460a5cf442a66b44cd527ec2712a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 2 May 2014 09:03:27 -0500 Subject: [PATCH 207/577] DRYing up some code. --- Eloquent/Model.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 05ec4aaa2..e3349675b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2187,11 +2187,9 @@ public function attributesToArray() { if ( ! array_key_exists($key, $attributes)) continue; - $value = $this->mutateAttribute( + $attributes[$key] = $this->mutateAttributeForArray( $key, $attributes[$key] ); - - $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() : $value; } // Here we will grab all of the appended, calculated attributes to this model @@ -2199,9 +2197,7 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->appends as $key) { - $value = $this->mutateAttribute($key, null); - - $attributes[$key] = $value instanceof ArrayableInterface ? $value->toArray() : $value; + $attributes[$key] = $this->mutateAttributeForArray($key, null); } return $attributes; @@ -2417,6 +2413,20 @@ protected function mutateAttribute($key, $value) return $this->{'get'.studly_case($key).'Attribute'}($value); } + /** + * Get the value of an attribute using its mutator for array conversion. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function mutateAttributeForArray($key, $value) + { + $value = $this->mutateAttribute($key, $value); + + return $value instanceof ArrayableInterface ? $value->toArray() : $value; + } + /** * Set a given attribute on the model. * From 5923fe2e51b893db3b876edd982066cf63aea2c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 2 May 2014 10:34:46 -0500 Subject: [PATCH 208/577] Fix order. --- Eloquent/Relations/MorphTo.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index bf0bceeb8..122d4789b 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -87,6 +87,21 @@ public function match(array $models, Collection $results, $relation) return $models; } + /** + * Associate the model instance to the given parent. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function associate(Model $model) + { + $this->parent->setAttribute($this->foreignKey, $model->getKey()); + + $this->parent->setAttribute($this->morphType, get_class($model)); + + return $this->parent->setRelation($this->relation, $model); + } + /** * Get the results of the relationship. * @@ -178,19 +193,4 @@ public function getDictionary() return $this->dictionary; } - /** - * Associate the model instance to the given parent. - * - * @param \Illuminate\Database\Eloquent\Model $model - * @return \Illuminate\Database\Eloquent\Model - */ - public function associate(Model $model) - { - $this->parent->setAttribute($this->foreignKey, $model->getKey()); - - $this->parent->setAttribute($this->morphType, get_class($model)); - - return $this->parent->setRelation($this->relation, $model); - } - } From 5692b950172edfda74b0dc2cc02222f713479e4d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 2 May 2014 11:11:20 -0500 Subject: [PATCH 209/577] Cleaning up a lot of code. --- Query/Builder.php | 53 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 6ae0ac6b6..7c1f0430f 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -127,6 +127,13 @@ class Builder { */ public $lock; + /** + * The backups of fields while doing a pagination count. + * + * @var array + */ + protected $backups = array(); + /** * The key that should be used when caching the query. * @@ -1549,21 +1556,16 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) */ public function getPaginationCount() { - list($orders, $this->orders) = array($this->orders, null); - list($offset, $this->offset) = array($this->offset, null); - list($limit, $this->limit) = array($this->limit, null); + $this->backupFieldsForCount(); $columns = $this->columns; - // Because some database engines may throw errors, or return incorrect - // results, if we leave the ordering, limit, and/or offset statements on - // the query, we will "back them up" and remove them from the query. - // Once we have the count we will put them back onto this. + // Because some database engines may throw errors if we leave the ordering + // statements on the query, we will "back them up" and remove them from + // the query. Once we have the count we will put them back onto this. $total = $this->count(); - $this->orders = $orders; - $this->offset = $offset; - $this->limit = $limit; + $this->restoreFieldsForCount(); // Once the query is run we need to put the old select columns back on the // instance so that the select query will run properly. Otherwise, they @@ -1573,6 +1575,37 @@ public function getPaginationCount() return $total; } + /** + * Backup certain fields for a pagination count. + * + * @return void + */ + protected function backupFieldsForCount() + { + foreach (array('orders', 'limit', 'offset') as $field) + { + $this->backups[$field] = $this->{$field}; + + $this->{$field} = null; + } + + } + + /** + * Restore certain fields for a pagination count. + * + * @return void + */ + protected function restoreFieldsForCount() + { + foreach (array('orders', 'limit', 'offset') as $field) + { + $this->{$field} = $this->backups[$field]; + } + + $this->backups = array(); + } + /** * Determine if any rows exist for the current query. * From c0d487f18f2e1fc875779ab5ccd11259bdc6cb40 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 2 May 2014 11:56:16 -0500 Subject: [PATCH 210/577] Use comment. --- Eloquent/Relations/BelongsToMany.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 4db712b00..e637a24e8 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -647,6 +647,10 @@ protected function attachNew(array $records, array $current, $touch = true) $changes['attached'][] = (int) $id; } + + // Now we'll try to update an existing pivot record with the attributes that were + // given to the method. If the model is actually updated we will add it to the + // list of updated pivot records so we return them back out to the consumer. elseif (count($attributes) > 0) { if ($this->updateExistingPivot($id, $attributes, $touch)) From 80cf1b040c4deaada0e4c20134749f9e0b9c31ec Mon Sep 17 00:00:00 2001 From: Alex Galletti Date: Wed, 7 May 2014 11:34:37 -0500 Subject: [PATCH 211/577] made Schema::getColumnListing method public --- Schema/Builder.php | 2 +- Schema/MySqlBuilder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Schema/Builder.php b/Schema/Builder.php index 51a0b4f50..43891d6c1 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -73,7 +73,7 @@ public function hasColumn($table, $column) * @param string $table * @return array */ - protected function getColumnListing($table) + public function getColumnListing($table) { $table = $this->connection->getTablePrefix().$table; diff --git a/Schema/MySqlBuilder.php b/Schema/MySqlBuilder.php index a0a1d2e0f..747268154 100755 --- a/Schema/MySqlBuilder.php +++ b/Schema/MySqlBuilder.php @@ -25,7 +25,7 @@ public function hasTable($table) * @param string $table * @return array */ - protected function getColumnListing($table) + public function getColumnListing($table) { $sql = $this->grammar->compileColumnExists(); From 386873fe9314fd123f792527dd1a9557856e12b3 Mon Sep 17 00:00:00 2001 From: 4dma Date: Thu, 8 May 2014 13:47:58 +0200 Subject: [PATCH 212/577] Resolve the right database connection. --- Migrations/Migrator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 3a1ecb525..1e5723c0a 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -323,9 +323,9 @@ public function getNotes() * * @return \Illuminate\Database\Connection */ - public function resolveConnection() + public function resolveConnection($connection) { - return $this->resolver->connection($this->connection); + return $this->resolver->connection($connection); } /** @@ -376,4 +376,4 @@ public function getFilesystem() return $this->files; } -} +} \ No newline at end of file From f56db366b24d93db3f1abc254e45b2242e0065cb Mon Sep 17 00:00:00 2001 From: Jake Shelby Date: Fri, 9 May 2014 10:03:33 -0600 Subject: [PATCH 213/577] Fixed bug that triggers relationship timestamp touch, even when nothing on the pivot has changed. --- Eloquent/Relations/BelongsToMany.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index e637a24e8..8599fa9cb 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -596,7 +596,11 @@ public function sync($ids, $detaching = true) $changes, $this->attachNew($records, $current, false) ); - $this->touchIfTouching(); + // Only going to touch if something was attached or updated + if (count($changes['attached']) || count($changes['updated'])) + { + $this->touchIfTouching(); + } return $changes; } From b9f7968402d94003d1bdbad3343dc19f653c2843 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 9 May 2014 19:22:55 +0100 Subject: [PATCH 214/577] Fixed master branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2dd4eac9f..ba8889558 100755 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "target-dir": "Illuminate/Database", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "minimum-stability": "dev" From b1d5ce1c184a69ce25d61bfb4eff7c677cf9e50b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 11 May 2014 18:59:45 +0100 Subject: [PATCH 215/577] 4.3 updates --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index ba8889558..2255565fb 100755 --- a/composer.json +++ b/composer.json @@ -10,17 +10,17 @@ ], "require": { "php": ">=5.4.0", - "illuminate/container": "4.2.*", - "illuminate/events": "4.2.*", - "illuminate/support": "4.2.*", + "illuminate/container": "4.3.*", + "illuminate/events": "4.3.*", + "illuminate/support": "4.3.*", "nesbot/carbon": "~1.0" }, "require-dev": { - "illuminate/cache": "4.2.*", - "illuminate/console": "4.2.*", - "illuminate/filesystem": "4.2.*", - "illuminate/pagination": "4.2.*", - "illuminate/support": "4.2.*", + "illuminate/cache": "4.3.*", + "illuminate/console": "4.3.*", + "illuminate/filesystem": "4.3.*", + "illuminate/pagination": "4.3.*", + "illuminate/support": "4.3.*", "mockery/mockery": "0.9.*", "phpunit/phpunit": "4.0.*" }, From 354f355ee3a14eda3f49dd8cadedc55260ece641 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 12 May 2014 14:45:24 +0200 Subject: [PATCH 216/577] Use ConfirmableTrait in Seeder Just like migrations --- Console/SeedCommand.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index c9197e633..98e009722 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -1,11 +1,14 @@ confirmToProceed()) return; + $this->resolver->setDefaultConnection($this->getDatabase()); $this->getSeeder()->run(); @@ -87,6 +92,8 @@ protected function getOptions() array('class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'DatabaseSeeder'), array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), ); } From db02408c6ef6bd1f349c27a1bdd23d7f438e16b5 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 12 May 2014 14:46:45 +0200 Subject: [PATCH 217/577] Force the seeding Otherwise it has to be confirmed twice. --- Console/Migrations/MigrateCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 0ce464044..3f78f81a0 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -82,7 +82,8 @@ public function fire() // a migration and a seed at the same time, as it is only this command. if ($this->input->getOption('seed')) { - $this->call('db:seed'); + $options = array('--force' => true); + $this->call('db:seed', $options); } } From c1ca8a7c039f6efa6a04d7f06d7f6e3b1cf3349b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 12 May 2014 13:44:31 -0500 Subject: [PATCH 218/577] Fix array call. --- Console/Migrations/MigrateCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 3f78f81a0..035192fd8 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -82,8 +82,7 @@ public function fire() // a migration and a seed at the same time, as it is only this command. if ($this->input->getOption('seed')) { - $options = array('--force' => true); - $this->call('db:seed', $options); + $this->call('db:seed', ['--force' => true]); } } From 73bfa7ce55baffb20e78dc7eb1c67cdaec38ceef Mon Sep 17 00:00:00 2001 From: Andy Holland Date: Tue, 13 May 2014 11:20:31 +0100 Subject: [PATCH 219/577] Prepare Query Bindings for Exception Prepare query bindings (format DateTime etc.) before passing them to Illuminate\Database\QueryException, this will prevent the "Object of class DateTime could not be converted to string" error that occurs when query errors are encountered. --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index cb6bde8fd..7dc813010 100755 --- a/Connection.php +++ b/Connection.php @@ -552,7 +552,7 @@ protected function run($query, $bindings, Closure $callback) // lot more helpful to the developer instead of just the database's errors. catch (\Exception $e) { - throw new QueryException($query, $bindings, $e); + throw new QueryException($query, $this->prepareBindings($bindings), $e); } // Once we have run the query we will calculate the time that it took to run and From 00babb09abdb2115c5380c3c1090ca8f533bd30b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 20 May 2014 08:21:41 -0500 Subject: [PATCH 220/577] Make column quoting more robust for greater security when passing an array of user input into update methods. --- Grammar.php | 4 +++- Query/Grammars/Grammar.php | 7 ------- Query/Grammars/MySqlGrammar.php | 20 +++++++++++++------- Query/Grammars/SqlServerGrammar.php | 20 +++++++++++++------- Schema/Grammars/MySqlGrammar.php | 20 +++++++++++++------- Schema/Grammars/PostgresGrammar.php | 7 ------- Schema/Grammars/SQLiteGrammar.php | 7 ------- Schema/Grammars/SqlServerGrammar.php | 7 ------- 8 files changed, 42 insertions(+), 50 deletions(-) diff --git a/Grammar.php b/Grammar.php index 6bb4cccf4..c67c4951e 100755 --- a/Grammar.php +++ b/Grammar.php @@ -83,7 +83,9 @@ public function wrap($value) */ protected function wrapValue($value) { - return $value !== '*' ? sprintf($this->wrapper, $value) : $value; + if ($value === '*') return $value; + + return '"'.str_replace('"', '""', $value).'"'; } /** diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 8d95942ef..2b7d36fab 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -5,13 +5,6 @@ class Grammar extends BaseGrammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '"%s"'; - /** * The components that make up a select clause. * diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index 668588bda..4c3fdc773 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -4,13 +4,6 @@ class MySqlGrammar extends Grammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '`%s`'; - /** * The components that make up a select clause. * @@ -99,4 +92,17 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '`'.str_replace('`', '``', $value).'`'; + } + } diff --git a/Query/Grammars/SqlServerGrammar.php b/Query/Grammars/SqlServerGrammar.php index ca5a23b17..f6faaf868 100755 --- a/Query/Grammars/SqlServerGrammar.php +++ b/Query/Grammars/SqlServerGrammar.php @@ -15,13 +15,6 @@ class SqlServerGrammar extends Grammar { '&', '&=', '|', '|=', '^', '^=', ); - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '[%s]'; - /** * Compile a select query into SQL. * @@ -217,4 +210,17 @@ public function getDateFormat() return 'Y-m-d H:i:s.000'; } + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '['.str_replace(']', ']]', $value).']'; + } + } diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 1022d3b50..de6d8da59 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -6,13 +6,6 @@ class MySqlGrammar extends Grammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '`%s`'; - /** * The possible column modifiers. * @@ -574,4 +567,17 @@ protected function modifyAfter(Blueprint $blueprint, Fluent $column) } } + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '`'.str_replace('`', '``', $value).'`'; + } + } diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index 6c3efbe56..76916170c 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -5,13 +5,6 @@ class PostgresGrammar extends Grammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '"%s"'; - /** * The possible column modifiers. * diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index d0199eec3..01be7b10d 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -6,13 +6,6 @@ class SQLiteGrammar extends Grammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '"%s"'; - /** * The possible column modifiers. * diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 83a96ae03..751969c0a 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -5,13 +5,6 @@ class SqlServerGrammar extends Grammar { - /** - * The keyword identifier wrapper format. - * - * @var string - */ - protected $wrapper = '"%s"'; - /** * The possible column modifiers. * From 7e35f2ad238c1b2024dd2083148d57c1a5f15dab Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 17 May 2014 17:17:28 +0100 Subject: [PATCH 221/577] Collection creation consistency --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index e5490e792..f930b8a2f 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,7 +77,7 @@ public function find($id, $columns = array('*')) */ public function findMany($id, $columns = array('*')) { - if (empty($id)) return new Collection; + if (empty($id)) return $this->model->newCollection(); $this->query->whereIn($this->model->getKeyName(), $id); From 2756b4383fab1e927165ddd93d17ff06aece9d5a Mon Sep 17 00:00:00 2001 From: Pavel Kirpichyov Date: Wed, 21 May 2014 10:38:19 +0300 Subject: [PATCH 222/577] [4.2] withTrashed() constraint does not work with morphTo() relations. --- Eloquent/Relations/MorphTo.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index 122d4789b..f03fdf952 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -28,6 +28,13 @@ class MorphTo extends BelongsTo { */ protected $dictionary = array(); + /* + * Indicates if soft-deleted model instances must be fetched or not + * + * @var bool + */ + protected $withTrashed = false; + /** * Create a new belongs to relationship instance. * @@ -150,6 +157,11 @@ protected function getResultsByType($type) { $instance = $this->createModelByType($type); + if ($this->withTrashed && $instance->query()->getMacro('withTrashed') !== null) + { + $instance = $instance->withTrashed(); + } + $key = $instance->getKeyName(); return $instance->whereIn($key, $this->gatherKeysByType($type)->all())->get(); @@ -193,4 +205,16 @@ public function getDictionary() return $this->dictionary; } + /** + * Fetch soft-deleted model instances with query + * + * @return MorphTo + */ + public function withTrashed() + { + $this->withTrashed = true; + + return $this; + } + } From e9e4b21e9c57c38313707f471bc28e3d429ce18e Mon Sep 17 00:00:00 2001 From: Pavel Kirpichyov Date: Wed, 21 May 2014 13:55:06 +0300 Subject: [PATCH 223/577] Assuming $instance is a Model instance, it should be ->newQuery(), not ->query() --- Eloquent/Relations/MorphTo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index f03fdf952..9dd9b5988 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -157,7 +157,7 @@ protected function getResultsByType($type) { $instance = $this->createModelByType($type); - if ($this->withTrashed && $instance->query()->getMacro('withTrashed') !== null) + if ($this->withTrashed && $instance->newQuery()->getMacro('withTrashed') !== null) { $instance = $instance->withTrashed(); } From a1711c4f7734a6d368e0e0aee1604c68e1501337 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 23 May 2014 08:34:25 -0500 Subject: [PATCH 224/577] Tweak wording. --- Eloquent/Relations/MorphTo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index 9dd9b5988..f68b12281 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -29,7 +29,7 @@ class MorphTo extends BelongsTo { protected $dictionary = array(); /* - * Indicates if soft-deleted model instances must be fetched or not + * Indicates if soft-deleted model instances should be fetched. * * @var bool */ From 3b4b5f41fc8a51990bd0f68d47a707abcdcc1ac9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 23 May 2014 11:17:35 -0500 Subject: [PATCH 225/577] Remove comment. --- Eloquent/Relations/BelongsToMany.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 8599fa9cb..16ebe728e 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -596,7 +596,6 @@ public function sync($ids, $detaching = true) $changes, $this->attachNew($records, $current, false) ); - // Only going to touch if something was attached or updated if (count($changes['attached']) || count($changes['updated'])) { $this->touchIfTouching(); From 770e5b81473c38bcf5e6db9765974199e524ada8 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 23 May 2014 17:40:19 +0100 Subject: [PATCH 226/577] Testing improvements --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2dd4eac9f..fa4bd4b19 100755 --- a/composer.json +++ b/composer.json @@ -20,9 +20,7 @@ "illuminate/console": "4.2.*", "illuminate/filesystem": "4.2.*", "illuminate/pagination": "4.2.*", - "illuminate/support": "4.2.*", - "mockery/mockery": "0.9.*", - "phpunit/phpunit": "4.0.*" + "illuminate/support": "4.2.*" }, "autoload": { "psr-0": { From 3a48e718c81a3ea0566d73005c304df1e148b68e Mon Sep 17 00:00:00 2001 From: Colin DeCarlo Date: Fri, 9 May 2014 08:21:06 -0400 Subject: [PATCH 227/577] Make the Console\Command and Console\Migrations\BaseCommand abstract --- Console/Migrations/BaseCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 7dfef5770..ce15ee8cb 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -2,7 +2,7 @@ use Illuminate\Console\Command; -class BaseCommand extends Command { +abstract class BaseCommand extends Command { /** * Get the path to the migration directory. From a737c138edd6f028b8e3812583ac3cf50b0debca Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Mon, 26 May 2014 11:51:59 +0200 Subject: [PATCH 228/577] implement Model::unsetConnectionResolver --- Eloquent/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e3349675b..af6861da4 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2801,6 +2801,16 @@ public static function setConnectionResolver(Resolver $resolver) static::$resolver = $resolver; } + /** + * Unset the connection resolver for models. + * + * @return void + */ + public static function unsetConnectionResolver() + { + static::$resolver = null; + } + /** * Get the event dispatcher instance. * From 878c811ef1296e23417556eb477289f3b181d36d Mon Sep 17 00:00:00 2001 From: 4dma Date: Mon, 26 May 2014 11:55:31 +0200 Subject: [PATCH 229/577] Added parameter to docblock. --- Migrations/Migrator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 1e5723c0a..d4ae5c428 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -321,6 +321,7 @@ public function getNotes() /** * Resolve the database connection instance. * + * @param string $connection * @return \Illuminate\Database\Connection */ public function resolveConnection($connection) From 78c6e06a99d3032cb91b257491c2fd276008f626 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 30 May 2014 11:01:49 -0500 Subject: [PATCH 230/577] Code organization. --- Eloquent/Model.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a7fd601a0..74ce1af8e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -149,6 +149,13 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ protected $with = array(); + /** + * The class name to be used in polymorphic relations. + * + * @var string + */ + protected $morphClass; + /** * Indicates if the model exists. * @@ -205,13 +212,6 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ protected static $mutatorCache = array(); - /** - * The class name to be used in polymorphic relations - * - * @var string - */ - protected $morphClass; - /** * The many to many relationship methods. * @@ -1817,16 +1817,6 @@ public function newPivot(Model $parent, array $attributes, $table, $exists) return new Pivot($parent, $attributes, $table, $exists); } - /** - * Get the class name for polymorphic relations. - * - * @return string - */ - public function getMorphClass() - { - return $this->morphClass ?: get_class($this); - } - /** * Get the table associated with the model. * @@ -1928,6 +1918,16 @@ protected function getMorphs($name, $type, $id) return array($type, $id); } + /** + * Get the class name for polymorphic relations. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass ?: get_class($this); + } + /** * Get the number of models to return per page. * From 0e29cf4d219d367e6c286e735cb39e461e7ae76e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 30 May 2014 11:49:34 -0500 Subject: [PATCH 231/577] Add space. --- Query/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Query/Builder.php b/Query/Builder.php index 674e999ab..c99cad7bc 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1692,6 +1692,7 @@ public function aggregate($function, $columns = array('*')) // that more select queries can be executed against the database without // the aggregate value getting in the way when the grammar builds it. $this->aggregate = null; + $this->columns = $previousColumns; if (isset($results[0])) From d3538aa671b1064bf40249098f2da47be0524230 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 30 May 2014 12:05:32 -0500 Subject: [PATCH 232/577] Fixing formatting. --- Eloquent/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e7ad78aaa..6232a7be7 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1443,7 +1443,8 @@ protected function performUpdate(Builder $query) // models are updated, giving them a chance to do any special processing. $dirty = $this->getDirty(); - if (count($dirty) > 0) { + if (count($dirty) > 0) + { $this->setKeysForSaveQuery($query)->update($dirty); $this->fireModelEvent('updated', false); From 96ef1f8f8fbba6f662ed28140a014480568c82d6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 30 May 2014 13:49:47 -0500 Subject: [PATCH 233/577] Fixing some formatting issues. --- Eloquent/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 25c7b8eb1..900aa9a59 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2200,9 +2200,9 @@ public function attributesToArray() { $attributes = $this->getArrayableAttributes(); - // Convert all attributes listed as dates to DateTime instances, then back - // to a string. This allows us to output date attributes in the same format - // as if we were to access them directly on the object. + // If an attribute is a date, we will cast it to a string after converting it + // to a DateTime / Carbon instance. This is so we will get some consistent + // formatting while accessing attributes vs. arraying / JSONing a model. foreach ($this->getDates() as $key) { if ( ! array_key_exists($key, $attributes)) continue; From 928bda2aa6784f4a42357c985d5e9d50673fff28 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 31 May 2014 20:08:40 -0500 Subject: [PATCH 234/577] Use isset instead of array_key_exists. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 900aa9a59..2a982cbd1 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2205,7 +2205,7 @@ public function attributesToArray() // formatting while accessing attributes vs. arraying / JSONing a model. foreach ($this->getDates() as $key) { - if ( ! array_key_exists($key, $attributes)) continue; + if ( ! isset($attributes[$key])) continue; $attributes[$key] = (string) $this->asDateTime($attributes[$key]); } From d6c2bffdc04d2d73b6ae82aab10647ddbda1daab Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 31 May 2014 20:57:51 -0500 Subject: [PATCH 235/577] Fix broken PR. --- Query/Builder.php | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index f74aa3314..66a9365c5 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1558,27 +1558,13 @@ public function getPaginationCount() { $this->backupFieldsForCount(); - $columns = $this->columns; - - // We have to check if the value is "null" so that the count function does - // not attempt to count an invalid string. Checking the value is better - // here because the count function already has an optional parameter. - if (is_null($columns)) - { - $total = $this->count(); - } - else - { - $total = $this->count($columns); - } + // Because some database engines may throw errors if we leave the ordering + // statements on the query, we will "back them up" and remove them from + // the query. Once we have the count we will put them back onto this. + $total = $this->count(); $this->restoreFieldsForCount(); - // Once the query is run we need to put the old select columns back on the - // instance so that the select query will run properly. Otherwise, they - // will be cleared, then the query will fire with all of the columns. - $this->columns = $columns; - return $total; } From db0b1996ada335f6d2518f3cfe768b92c8055f58 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 30 May 2014 12:51:06 +0100 Subject: [PATCH 236/577] Forward thinking for composer --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f8efb803e..82e3989e5 100755 --- a/composer.json +++ b/composer.json @@ -23,11 +23,10 @@ "illuminate/support": "4.3.*" }, "autoload": { - "psr-0": { - "Illuminate\\Database": "" + "psr-4": { + "Illuminate\\Database\\": "" } }, - "target-dir": "Illuminate/Database", "extra": { "branch-alias": { "dev-master": "4.3-dev" From 346c96e41cd07588e3bc286311549f35285193a2 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 1 Jun 2014 23:46:36 +0100 Subject: [PATCH 237/577] Minor cs fixes --- Console/SeedCommand.php | 4 ++-- Migrations/Migrator.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index 98e009722..04d3e6d02 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -51,7 +51,7 @@ public function __construct(Resolver $resolver) public function fire() { if ( ! $this->confirmToProceed()) return; - + $this->resolver->setDefaultConnection($this->getDatabase()); $this->getSeeder()->run(); @@ -92,7 +92,7 @@ protected function getOptions() array('class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'DatabaseSeeder'), array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'), - + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), ); } diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index d4ae5c428..d41111a3f 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -377,4 +377,4 @@ public function getFilesystem() return $this->files; } -} \ No newline at end of file +} From b1b0cfc66e43f032c81bf183cb10bb974c9dc10d Mon Sep 17 00:00:00 2001 From: Pavel Kirpichyov Date: Mon, 2 Jun 2014 16:20:38 +0300 Subject: [PATCH 238/577] [4.2] Gey keyName before instance can be translated into builder --- Eloquent/Relations/MorphTo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index f68b12281..5a0ba2599 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -157,13 +157,13 @@ protected function getResultsByType($type) { $instance = $this->createModelByType($type); + $key = $instance->getKeyName(); + if ($this->withTrashed && $instance->newQuery()->getMacro('withTrashed') !== null) { $instance = $instance->withTrashed(); } - $key = $instance->getKeyName(); - return $instance->whereIn($key, $this->gatherKeysByType($type)->all())->get(); } From f79794ba226cf18bf89b6435acfef904a6ec2238 Mon Sep 17 00:00:00 2001 From: Jake Shelby Date: Mon, 2 Jun 2014 14:46:06 -0600 Subject: [PATCH 239/577] Eloquent Pivot - Make sure raw attributes setting also set's original data Fixes bug that calls db update from pivot models that haven't even changed --- Eloquent/Relations/Pivot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/Pivot.php b/Eloquent/Relations/Pivot.php index 2b012975f..9645062cd 100755 --- a/Eloquent/Relations/Pivot.php +++ b/Eloquent/Relations/Pivot.php @@ -49,7 +49,7 @@ public function __construct(Model $parent, $attributes, $table, $exists = false) // The pivot model is a "dynamic" model since we will set the tables dynamically // for the instance. This allows it work for any intermediate tables for the // many to many relationship that are defined by this developer's classes. - $this->setRawAttributes($attributes); + $this->setRawAttributes($attributes, true); $this->setTable($table); From fe84262413ab74a0dcac46137db54eca629b9ed6 Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Mon, 2 Jun 2014 14:44:08 -0700 Subject: [PATCH 240/577] Eliminate array_merge() on insert call for performance --- Query/Builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index f582a2f68..4cca94778 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1776,7 +1776,10 @@ public function insert(array $values) foreach ($values as $record) { - $bindings = array_merge($bindings, array_values($record)); + foreach ($record as $value) + { + $bindings[] = $value; + } } $sql = $this->grammar->compileInsert($this, $values); From 23b8ac712afb664fdbe2f2ebdd17035a74bd7ead Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Tue, 3 Jun 2014 14:52:07 -0700 Subject: [PATCH 241/577] Respect DELETED_AT constant if set for soft deletes --- Eloquent/SoftDeletingTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index 639a1c437..d0589c51d 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -154,7 +154,7 @@ public static function restored($callback) */ public function getDeletedAtColumn() { - return 'deleted_at'; + return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at'; } /** From b6db5f05a8b4cf0ba750431c181528912300c4da Mon Sep 17 00:00:00 2001 From: Pavel Kirpichyov Date: Wed, 4 Jun 2014 09:31:54 +0300 Subject: [PATCH 242/577] [4.2] Always operate with query builder to prevent possible bugs --- Eloquent/Relations/MorphTo.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index 5a0ba2599..e04d34158 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -159,12 +159,14 @@ protected function getResultsByType($type) $key = $instance->getKeyName(); - if ($this->withTrashed && $instance->newQuery()->getMacro('withTrashed') !== null) + $query = $instance->newQuery(); + + if ($this->withTrashed && $query->getMacro('withTrashed') !== null) { - $instance = $instance->withTrashed(); + $query = $query->withTrashed(); } - return $instance->whereIn($key, $this->gatherKeysByType($type)->all())->get(); + return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get(); } /** From ac29fa97a5c3cd946a74ba84dd605a56d3638bcf Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Thu, 5 Jun 2014 09:48:47 +0100 Subject: [PATCH 243/577] Added Builder::rightJoin() and Builder::rightJoinWhere() --- Query/Builder.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index f582a2f68..63b11bf1e 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -342,6 +342,34 @@ public function leftJoinWhere($table, $one, $operator, $two) return $this->joinWhere($table, $one, $operator, $two, 'left'); } + /** + * Add a right join to the query. + * + * @param string $table + * @param string $first + * @param string $operator + * @param string $second + * @return \Illuminate\Database\Query\Builder|static + */ + public function rightJoin($table, $first, $operator = null, $second = null) + { + return $this->join($table, $first, $operator, $second, 'right'); + } + + /** + * Add a "right join where" clause to the query. + * + * @param string $table + * @param string $first + * @param string $operator + * @param string $two + * @return \Illuminate\Database\Query\Builder|static + */ + public function rightJoinWhere($table, $one, $operator, $two) + { + return $this->joinWhere($table, $one, $operator, $two, 'right'); + } + /** * Add a basic where clause to the query. * From fdeeccb2c008ec8f22d148137853cb380019dd03 Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Thu, 5 Jun 2014 09:55:48 +0100 Subject: [PATCH 244/577] sync() triggered after 'saved' event, so listeners can detect dirty properties that got saved --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2192e931f..745e711af 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1379,10 +1379,10 @@ public function save(array $options = array()) */ protected function finishSave(array $options) { - $this->syncOriginal(); - $this->fireModelEvent('saved', false); + $this->syncOriginal(); + if (array_get($options, 'touch', true)) $this->touchOwners(); } From 5207a527c2b41839fda32d2fd1654a4fc8004ea6 Mon Sep 17 00:00:00 2001 From: crynobone Date: Fri, 6 Jun 2014 22:12:08 +0800 Subject: [PATCH 245/577] Only create a "config" instance if only it not yet created. On one of the project I'm working right now, I'm using both Config and Capsule component, since I register config service location first and then capsule, all the preloaded config is destroy on the config service location is converted to instance of Illuminate\Support\Fluent which is not ideal in my use case. Signed-off-by: crynobone --- Capsule/Manager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 812dd1cb4..6283e3004 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -60,7 +60,10 @@ protected function setupContainer($container) { $this->container = $container ?: new Container; - $this->container->instance('config', new Fluent); + if ( ! $this->container->bound('config')) + { + $this->container->instance('config', new Fluent); + } } /** From 6ce59adae08fb1598f4963919614bdc4ad8ceb46 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Jun 2014 09:36:02 -0500 Subject: [PATCH 246/577] Set default value on touch. --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 16ebe728e..eefd51a8d 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -673,7 +673,7 @@ protected function attachNew(array $records, array $current, $touch = true) * @param bool $touch * @return void */ - public function updateExistingPivot($id, array $attributes, $touch) + public function updateExistingPivot($id, array $attributes, $touch = true) { if (in_array($this->updatedAt(), $this->pivotColumns)) { From 77185db65daaf0f5a7d9e0d0f03cb9d3e8c6af00 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Jun 2014 11:07:01 -0500 Subject: [PATCH 247/577] Add note. --- Eloquent/Relations/MorphPivot.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index b0385903a..ec3c1b873 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -7,6 +7,8 @@ class MorphPivot extends Pivot { /** * The type of the polymorphic relation. * + * Explicitly define this so it's not included in saved attributes. + * * @var string */ protected $morphType; From 6147a8385c9e1d11c9875a89a4ec1c6bd6aee84d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 6 Jun 2014 18:52:06 +0200 Subject: [PATCH 248/577] Add updateOrCreate() function --- Eloquent/Model.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 745e711af..172ad3e42 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -558,6 +558,21 @@ public static function firstOrNew(array $attributes) return new static($attributes); } + /** + * Create or update a record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public static function updateOrCreate(array $attributes, array $values = []) + { + $instance = static::firstOrNew($attributes); + $instance->fill($values)->save(); + + return $instance; + } + /** * Get the first model for the given attributes. * From 3761662e987b754ab189a6e962f4144df5fe8ca7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Jun 2014 12:11:10 -0500 Subject: [PATCH 249/577] Cleaning up code. --- Query/Builder.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 3fa56fa84..ec0fbe31d 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -241,13 +241,14 @@ public function selectSub($query, $as) if ($query instanceof Closure) { $callback = $query; - $query = $this->newQuery(); - $callback($query); + + $callback($query = $this->newQuery()); } if ($query instanceof Builder) { $bindings = $query->getBindings(); + $query = $query->toSql(); } elseif (is_string($query)) @@ -256,16 +257,10 @@ public function selectSub($query, $as) } else { - $type = is_object($query) ? get_class($query) : gettype($query); - $message = "Argument #1 passed to selectSub must be an SQL string, query builder or closure, {$type} given"; - throw new \InvalidArgumentException($message); + throw new \InvalidArgumentException; } - $as = $this->grammar->wrap($as); - - $query = '(' . $query . ') as ' . $as; - - return $this->selectRaw($query, $bindings); + return $this->selectRaw('('.$query.') as '.$this->grammar->wrap($as), $bindings); } /** From 33b20ea9d348a8424cbe5e82c3c2e319650ce093 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Jun 2014 12:12:41 -0500 Subject: [PATCH 250/577] Spacing. --- Eloquent/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 172ad3e42..b69e27e3a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -565,9 +565,10 @@ public static function firstOrNew(array $attributes) * @param array $values * @return \Illuminate\Database\Eloquent\Model */ - public static function updateOrCreate(array $attributes, array $values = []) + public static function updateOrCreate(array $attributes, array $values = array()) { $instance = static::firstOrNew($attributes); + $instance->fill($values)->save(); return $instance; From a73ed8f5dcad77d4ec2a79aff3aa2c2aea34dd3d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 6 Jun 2014 22:49:41 +0100 Subject: [PATCH 251/577] Updated connection interface --- ConnectionInterface.php | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/ConnectionInterface.php b/ConnectionInterface.php index f6ff5e0b5..131a18572 100755 --- a/ConnectionInterface.php +++ b/ConnectionInterface.php @@ -4,6 +4,23 @@ interface ConnectionInterface { + /** + * Begin a fluent query against a database table. + * + * @param string $table + * @return \Illuminate\Database\Query\Builder + */ + public function table($table); + + /** + * Get a new raw query expression. + * + * @param mixed $value + * @return \Illuminate\Database\Query\Expression + */ + public function raw($value); + + /** * Run a select statement and return a single result. * @@ -58,12 +75,75 @@ public function delete($query, $bindings = array()); */ public function statement($query, $bindings = array()); + /** + * Run an SQL statement and get the number of rows affected. + * + * @param string $query + * @param array $bindings + * @return int + */ + public function affectingStatement($query, $bindings = array()); + + /** + * Run a raw, unprepared query against the PDO connection. + * + * @param string $query + * @return bool + */ + public function unprepared($query); + + /** + * Prepare the query bindings for execution. + * + * @param array $bindings + * @return array + */ + public function prepareBindings(array $bindings); + /** * Execute a Closure within a transaction. * * @param Closure $callback * @return mixed + * + * @throws \Exception */ public function transaction(Closure $callback); + /** + * Start a new database transaction. + * + * @return void + */ + public function beginTransaction(); + + /** + * Commit the active database transaction. + * + * @return void + */ + public function commit(); + + /** + * Rollback the active database transaction. + * + * @return void + */ + public function rollBack(); + + /** + * Get the number of active transactions. + * + * @return int + */ + public function transactionLevel(); + + /** + * Execute the given callback in "dry run" mode. + * + * @param Closure $callback + * @return array + */ + public function pretend(Closure $callback); + } From df54098ec017dc6f1620c7918384590173b2464b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 6 Jun 2014 23:06:02 +0100 Subject: [PATCH 252/577] Removed extra line --- ConnectionInterface.php | 1 - 1 file changed, 1 deletion(-) diff --git a/ConnectionInterface.php b/ConnectionInterface.php index 131a18572..a41f2bb16 100755 --- a/ConnectionInterface.php +++ b/ConnectionInterface.php @@ -20,7 +20,6 @@ public function table($table); */ public function raw($value); - /** * Run a select statement and return a single result. * From 057636366b81c5bc013c44c2599c5767c05aff00 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Jun 2014 21:32:10 -0500 Subject: [PATCH 253/577] Revert abstract class change. --- Console/Migrations/BaseCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index ce15ee8cb..7dfef5770 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -2,7 +2,7 @@ use Illuminate\Console\Command; -abstract class BaseCommand extends Command { +class BaseCommand extends Command { /** * Get the path to the migration directory. From da5eef7fcd1fc33c06ed3223f75bdde7fa7fb4b8 Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Sun, 8 Jun 2014 11:43:16 -0700 Subject: [PATCH 254/577] Adding `$table->rememberToken()` method to schema builder Includes tests Signed-off-by: Adam Engebretson --- Schema/Blueprint.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 836d013c2..4f812be7a 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -672,6 +672,11 @@ public function morphs($name) $this->index(array("{$name}_id", "{$name}_type")); } + public function rememberToken() + { + $this->string('remember_token', 100)->nullable(); + } + /** * Create a new drop index command on the blueprint. * From ec83d6710c1079e693ebda010c01c106f544b825 Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Sun, 8 Jun 2014 11:50:41 -0700 Subject: [PATCH 255/577] Adding `$table->rememberToken()` DocBlocks Signed-off-by: Adam Engebretson --- Schema/Blueprint.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 4f812be7a..64f38455c 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -672,6 +672,11 @@ public function morphs($name) $this->index(array("{$name}_id", "{$name}_type")); } + /** + * Adds `remember_token` column to the table. + * + * @return void + */ public function rememberToken() { $this->string('remember_token', 100)->nullable(); From 36a6dac78511e4cab12438e4969645e423992ef2 Mon Sep 17 00:00:00 2001 From: Ryan Nielson Date: Thu, 12 Jun 2014 12:34:40 -0300 Subject: [PATCH 256/577] migrate:refresh command now properly passed force option to reset and migrate --- Console/Migrations/RefreshCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index ad71ae442..8056390de 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -32,13 +32,14 @@ public function fire() if ( ! $this->confirmToProceed()) return; $database = $this->input->getOption('database'); + $force = $this->input->getOption('force'); - $this->call('migrate:reset', array('--database' => $database)); + $this->call('migrate:reset', array('--database' => $database, '--force' => $force)); // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute // them in succession. We'll also see if we need to re-seed the database. - $this->call('migrate', array('--database' => $database)); + $this->call('migrate', array('--database' => $database, '--force' => $force)); if ($this->needsSeeding()) { From 8ad5c5b9e95ef69e5734a0702ee6f0d0771c369d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 13 Jun 2014 08:29:48 -0500 Subject: [PATCH 257/577] Fix spacing. --- Console/Migrations/RefreshCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Console/Migrations/RefreshCommand.php b/Console/Migrations/RefreshCommand.php index 8056390de..2adc6e82e 100755 --- a/Console/Migrations/RefreshCommand.php +++ b/Console/Migrations/RefreshCommand.php @@ -32,14 +32,19 @@ public function fire() if ( ! $this->confirmToProceed()) return; $database = $this->input->getOption('database'); + $force = $this->input->getOption('force'); - $this->call('migrate:reset', array('--database' => $database, '--force' => $force)); + $this->call('migrate:reset', array( + '--database' => $database, '--force' => $force + )); // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute // them in succession. We'll also see if we need to re-seed the database. - $this->call('migrate', array('--database' => $database, '--force' => $force)); + $this->call('migrate', array( + '--database' => $database, '--force' => $force + )); if ($this->needsSeeding()) { From fd76d0c9a65a8eb601d764fa424053bc7fe625c6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 13 Jun 2014 14:28:23 -0500 Subject: [PATCH 258/577] Working on documentation block. --- Schema/Blueprint.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 64f38455c..8d660c630 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -673,8 +673,8 @@ public function morphs($name) } /** - * Adds `remember_token` column to the table. - * + * Adds the `remember_token` column to the table. + * * @return void */ public function rememberToken() From 8ea4b9db9908db1cf9bcae8575f77642fa93b71c Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Sun, 15 Jun 2014 12:58:28 +0300 Subject: [PATCH 259/577] Flagged exists as true when restoring the model --- Eloquent/SoftDeletingTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index d0589c51d..1a23149ea 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -84,6 +84,7 @@ public function restore() // Once we have saved the model, we will fire the "restored" event so this // developer will do anything they need to after a restore operation is // totally finished. Then we will return the result of the save call. + $this->exists = true; $result = $this->save(); $this->fireModelEvent('restored', false); From c8ee4d1dbd826296c09c1536cb5f665b7ad1ecb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Gon=C3=A7alves?= Date: Thu, 19 Jun 2014 01:47:45 -0300 Subject: [PATCH 260/577] Add comment in MySQLGrammar --- Schema/Grammars/MySqlGrammar.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 84a5088f7..4e2895113 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -11,7 +11,7 @@ class MySqlGrammar extends Grammar { * * @var array */ - protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'After'); + protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'After', 'Comment'); /** * The possible column serials @@ -567,6 +567,21 @@ protected function modifyAfter(Blueprint $blueprint, Fluent $column) } } + /** + * Get the SQL for an "comment" column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyComment(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->comment)) + { + return ' comment "' . $column->comment . '"'; + } + } + /** * Wrap a single string in keyword identifiers. * From ec3149c90c766ad56bbbf211d891ba40a27e60d9 Mon Sep 17 00:00:00 2001 From: etienne Date: Thu, 19 Jun 2014 12:12:50 +0200 Subject: [PATCH 261/577] add priority in eloquent auto events (creating, created, upstating, etc.) --- Eloquent/Model.php | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b69e27e3a..a297363d0 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1130,88 +1130,96 @@ protected function performDeleteOnModel() * Register a saving model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function saving($callback) + public static function saving($callback, $priority = 0) { - static::registerModelEvent('saving', $callback); + static::registerModelEvent('saving', $callback, $priority); } /** * Register a saved model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function saved($callback) + public static function saved($callback, $priority = 0) { - static::registerModelEvent('saved', $callback); + static::registerModelEvent('saved', $callback, $priority); } /** * Register an updating model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function updating($callback) + public static function updating($callback, $priority = 0) { - static::registerModelEvent('updating', $callback); + static::registerModelEvent('updating', $callback, $priority); } /** * Register an updated model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function updated($callback) + public static function updated($callback, $priority = 0) { - static::registerModelEvent('updated', $callback); + static::registerModelEvent('updated', $callback, $priority); } /** * Register a creating model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function creating($callback) + public static function creating($callback, $priority = 0) { - static::registerModelEvent('creating', $callback); + static::registerModelEvent('creating', $callback, $priority); } /** * Register a created model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function created($callback) + public static function created($callback, $priority = 0) { - static::registerModelEvent('created', $callback); + static::registerModelEvent('created', $callback, $priority); } /** * Register a deleting model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function deleting($callback) + public static function deleting($callback, $priority = 0) { - static::registerModelEvent('deleting', $callback); + static::registerModelEvent('deleting', $callback, $priority); } /** * Register a deleted model event with the dispatcher. * * @param \Closure|string $callback + * @param int $priority * @return void */ - public static function deleted($callback) + public static function deleted($callback, $priority = 0) { - static::registerModelEvent('deleted', $callback); + static::registerModelEvent('deleted', $callback, $priority); } /** @@ -1238,13 +1246,13 @@ public static function flushEventListeners() * @param \Closure|string $callback * @return void */ - protected static function registerModelEvent($event, $callback) + protected static function registerModelEvent($event, $callback, $priority = 0) { if (isset(static::$dispatcher)) { $name = get_called_class(); - static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback); + static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback, $priority); } } From 1936450aac748a83cc37eeac6f021d1693ef61f3 Mon Sep 17 00:00:00 2001 From: etienne Date: Thu, 19 Jun 2014 12:18:36 +0200 Subject: [PATCH 262/577] use of tab instead of 4 spaces --- Eloquent/Model.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a297363d0..542963f01 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1130,7 +1130,7 @@ protected function performDeleteOnModel() * Register a saving model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function saving($callback, $priority = 0) @@ -1142,7 +1142,7 @@ public static function saving($callback, $priority = 0) * Register a saved model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function saved($callback, $priority = 0) @@ -1154,7 +1154,7 @@ public static function saved($callback, $priority = 0) * Register an updating model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function updating($callback, $priority = 0) @@ -1166,7 +1166,7 @@ public static function updating($callback, $priority = 0) * Register an updated model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function updated($callback, $priority = 0) @@ -1178,7 +1178,7 @@ public static function updated($callback, $priority = 0) * Register a creating model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function creating($callback, $priority = 0) @@ -1190,10 +1190,10 @@ public static function creating($callback, $priority = 0) * Register a created model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ - public static function created($callback, $priority = 0) + public static function created($callback, $priority = 0) { static::registerModelEvent('created', $callback, $priority); } @@ -1202,7 +1202,7 @@ public static function created($callback, $priority = 0) * Register a deleting model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function deleting($callback, $priority = 0) @@ -1214,7 +1214,7 @@ public static function deleting($callback, $priority = 0) * Register a deleted model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function deleted($callback, $priority = 0) @@ -1244,6 +1244,7 @@ public static function flushEventListeners() * * @param string $event * @param \Closure|string $callback + * @param int $priority * @return void */ protected static function registerModelEvent($event, $callback, $priority = 0) From 78796d0fa2482e60a4fd7ef3dd4bcb712495c13c Mon Sep 17 00:00:00 2001 From: Mattia Trapani Date: Thu, 19 Jun 2014 20:15:16 +0200 Subject: [PATCH 263/577] performUpdate should return false if no update is performed --- Eloquent/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2a982cbd1..03951762c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1449,9 +1449,11 @@ protected function performUpdate(Builder $query) $this->fireModelEvent('updated', false); } + + return true; } - return true; + return false; } /** From 09c65f3bdd3fed074b43bdc7e649e54f26365d2f Mon Sep 17 00:00:00 2001 From: Nitin Tutlani Date: Thu, 19 Jun 2014 18:27:41 +0000 Subject: [PATCH 264/577] Added support for change column in Schema --- Schema/Blueprint.php | 35 +++++++++- Schema/Grammars/Grammar.php | 124 +++++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 5 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 8d660c630..7ba600fe5 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -103,11 +103,18 @@ public function toSql(Connection $connection, Grammar $grammar) */ protected function addImpliedCommands() { - if (count($this->columns) > 0 && ! $this->creating()) + //compileAdd command to add columns + if (count($this->addedColumns()) > 0 && ! $this->creating()) { array_unshift($this->commands, $this->createCommand('add')); } + //compileChange command to modify columns + if (count($this->changedColumns()) > 0 && ! $this->creating()) + { + array_unshift($this->commands, $this->createCommand('change')); + } + $this->addFluentIndexes(); } @@ -814,7 +821,7 @@ public function getTable() } /** - * Get the columns that should be added. + * Get the columns on the blueprint. * * @return array */ @@ -833,4 +840,28 @@ public function getCommands() return $this->commands; } + /** + * Get the columns on the blueprint that should be added. + * + * @return array + */ + public function addedColumns() + { + return array_filter($this->columns, function($column) { + return !$column->change; + }); + } + + /** + * Get the columns on the blueprint that should be changed. + * + * @return array + */ + public function changedColumns() + { + return array_filter($this->columns, function($column) { + return !!$column->change; + }); + } + } diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index c5c57ccef..0fae9cc11 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -2,7 +2,10 @@ use Illuminate\Support\Fluent; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Types\Type; use Illuminate\Database\Connection; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; @@ -108,14 +111,15 @@ public function compileForeign(Blueprint $blueprint, Fluent $command) /** * Compile the blueprint's column definitions. * - * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param bool $change Filter added/changed columns * @return array */ - protected function getColumns(Blueprint $blueprint) + protected function getColumns(Blueprint $blueprint, $change = false) { $columns = array(); - foreach ($blueprint->getColumns() as $column) + foreach ( !$change ? $blueprint->addedColumns() : $blueprint->changedColumns() as $column) { // Each of the column types have their own compiler functions which are tasked // with turning the column definition into its SQL format for this platform @@ -266,4 +270,118 @@ protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $sch return $tableDiff; } + /** + * @param Blueprint $blueprint + * @param Fluent $command + * @param Connection $connection + * @return array + */ + public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) + { + $schema = $connection->getDoctrineSchemaManager(); + + $tableDiff = $this->getChangedDiff($blueprint, $schema); + + if($tableDiff !== false) + { + return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); + } + + return []; + } + + /** + * @param Blueprint $blueprint + * @param SchemaManager $schema + * @return bool|TableDiff + */ + protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema) + { + $tableName = $this->getTablePrefix().$blueprint->getTable(); + + $table = $schema->listTableDetails($tableName); + + $tableClone = $this->getChangedColumnsClone($blueprint, $table); + + $comparator = new Comparator; + + $tableDiff = $comparator->diffTable($table, $tableClone); + + return $tableDiff; + } + + /** + * Clone Doctrine table and update column definitions based on blueprint. + * + * @param Blueprint $blueprint + * @param Table $table + * @return Table + */ + protected function getChangedColumnsClone(Blueprint $blueprint, Table $table) + { + $tableClone = clone $table; + + foreach($blueprint->changedColumns() as $fluentColumn) + { + $tableClone = $tableClone->changeColumn($fluentColumn['name'], array('type' => Type::getType($fluentColumn['type']))); + + $column = $tableClone->getColumn($fluentColumn['name']); + + //Skipable boolean attributes must be reset + $column->setNotnull(true); + $column->setUnsigned(false); + + foreach ($fluentColumn->getAttributes() as $key => $value) + { + + $option = $this->getFluentAttributeDoctrineColumnOptionName($key); + + //Behavior of notnull is opposite of nullable + if($option == 'notnull') $value = !$value; + + if( ! is_null($option) ) + { + $method = 'set'.ucfirst($option); + + if (method_exists($column, $method)) + { + $column->{$method}($value); + } + } + } + } + + return $tableClone; + } + + /** + * Returns comparable doctrine option for fluent attribute name. + * + * @param $attribute + * @return string + */ + protected function getFluentAttributeDoctrineColumnOptionName($attribute) { + $option = null; + switch($attribute) + { + case 'type': + case 'name': + //No option for type and name + break; + case 'nullable': + $option = 'notnull'; + break; + case 'total': + $option = 'precision'; + break; + case 'places': + $option = 'scale'; + break; + default: + $option = $attribute; + break; + } + return $option; + } + } From 22928f584f9235c16a629569090ab3180cb6c9c3 Mon Sep 17 00:00:00 2001 From: silentworks Date: Thu, 19 Jun 2014 23:39:43 +0100 Subject: [PATCH 265/577] Added in status command for migrations --- Console/Migrations/StatusCommand.php | 96 ++++++++++++++++++++++++++++ MigrationServiceProvider.php | 19 ++++-- 2 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 Console/Migrations/StatusCommand.php diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php new file mode 100644 index 000000000..1e02d0a12 --- /dev/null +++ b/Console/Migrations/StatusCommand.php @@ -0,0 +1,96 @@ +migrator = $migrator; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + $this->migrator->setConnection($this->input->getOption('database')); + + $this->output->writeln(" Status Migration Name "); + $this->output->writeln("--------------------------------------------"); + + $versions = $this->migrator->getRepository()->getRan(); + $migrationFiles = $this->migrator->getMigrationFiles($this->getMigrationPath()); + + foreach ($migrationFiles as $migration) + { + if (in_array($migration, $versions)) + { + $status = " up "; + unset($versions[array_search($migration, $versions)]); + } + else + { + $status = " down "; + } + + $this->output->writeln("{$status} {$migration}"); + } + + foreach ($versions as $missing) + { + $this->output->writeln(" up {$missing} *** MISSING ***"); + } + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null), + + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + + array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null), + + array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null), + ); + } + +} diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 797d7fb46..afb645011 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -9,6 +9,7 @@ use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\Console\Migrations\RollbackCommand; use Illuminate\Database\Console\Migrations\MigrateMakeCommand; +use Illuminate\Database\Console\Migrations\StatusCommand; use Illuminate\Database\Migrations\DatabaseMigrationRepository; class MigrationServiceProvider extends ServiceProvider { @@ -77,7 +78,7 @@ protected function registerMigrator() */ protected function registerCommands() { - $commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make'); + $commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make', 'Status'); // We'll simply spin through the list of commands that are migration related // and register each one of them with an application container. They will @@ -93,7 +94,8 @@ protected function registerCommands() $this->commands( 'command.migrate', 'command.migrate.make', 'command.migrate.install', 'command.migrate.rollback', - 'command.migrate.reset', 'command.migrate.refresh' + 'command.migrate.reset', 'command.migrate.refresh', + 'command.migrate.status' ); } @@ -151,6 +153,14 @@ protected function registerRefreshCommand() }); } + protected function registerStatusCommand() + { + $this->app->bindShared('command.migrate.status', function($app) + { + return new StatusCommand($app['migrator']); + }); + } + /** * Register the "install" migration command. * @@ -165,7 +175,7 @@ protected function registerInstallCommand() } /** - * Register the "install" migration command. + * Register the "make" migration command. * * @return void */ @@ -200,7 +210,8 @@ public function provides() 'migrator', 'migration.repository', 'command.migrate', 'command.migrate.rollback', 'command.migrate.reset', 'command.migrate.refresh', 'command.migrate.install', - 'migration.creator', 'command.migrate.make', + 'command.migrate.status', 'migration.creator', + 'command.migrate.make', ); } From 1ce97d98757b3ce7123dadf89444de5f481c977b Mon Sep 17 00:00:00 2001 From: silentworks Date: Thu, 19 Jun 2014 23:42:13 +0100 Subject: [PATCH 266/577] Updated coding style to match Laravel's coding style guide --- MigrationServiceProvider.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index afb645011..7daa29535 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -95,7 +95,7 @@ protected function registerCommands() 'command.migrate', 'command.migrate.make', 'command.migrate.install', 'command.migrate.rollback', 'command.migrate.reset', 'command.migrate.refresh', - 'command.migrate.status' + 'command.migrate.status' ); } @@ -153,13 +153,13 @@ protected function registerRefreshCommand() }); } - protected function registerStatusCommand() - { - $this->app->bindShared('command.migrate.status', function($app) - { - return new StatusCommand($app['migrator']); - }); - } + protected function registerStatusCommand() + { + $this->app->bindShared('command.migrate.status', function($app) + { + return new StatusCommand($app['migrator']); + }); + } /** * Register the "install" migration command. @@ -210,8 +210,8 @@ public function provides() 'migrator', 'migration.repository', 'command.migrate', 'command.migrate.rollback', 'command.migrate.reset', 'command.migrate.refresh', 'command.migrate.install', - 'command.migrate.status', 'migration.creator', - 'command.migrate.make', + 'command.migrate.status', 'migration.creator', + 'command.migrate.make', ); } From e3c38a217ab70d4f7608484348e098a5fe2536cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Gon=C3=A7alves?= Date: Fri, 20 Jun 2014 09:51:51 -0300 Subject: [PATCH 267/577] Fixing indentation modifyComment function --- Schema/Grammars/MySqlGrammar.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 4e2895113..9dcef37cb 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -567,20 +567,20 @@ protected function modifyAfter(Blueprint $blueprint, Fluent $column) } } - /** - * Get the SQL for an "comment" column modifier. - * - * @param \Illuminate\Database\Schema\Blueprint $blueprint - * @param \Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifyComment(Blueprint $blueprint, Fluent $column) - { - if ( ! is_null($column->comment)) - { - return ' comment "' . $column->comment . '"'; - } - } + /** + * Get the SQL for an "comment" column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyComment(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->comment)) + { + return ' comment "' . $column->comment . '"'; + } + } /** * Wrap a single string in keyword identifiers. From e17990bc5bb8c95d89c9e6361f17718dccf5da4c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 21 Jun 2014 12:46:59 -0500 Subject: [PATCH 268/577] Adding array wheres. --- Query/Builder.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index dfc4a3d6d..ab7da690a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -383,6 +383,20 @@ public function rightJoinWhere($table, $one, $operator, $two) */ public function where($column, $operator = null, $value = null, $boolean = 'and') { + // If the column is an array, we will assume it is an array of key-value pairs + // and can add them each as a where clause. We will maintain the boolean we + // received when the method was called and pass it onto the other wheres. + if (is_array($column)) + { + foreach ($column as $innerKey => $innerValue) + { + $this->where($innerKey, '=', $innerValue, $boolean); + } + } + + // Here we will make some assumptions about the operator. If only 2 values are + // passed to the method, we will assume that the operator is an equals sign + // and keep going. Otherwise, we'll require the operator to be passed in. if (func_num_args() == 2) { list($value, $operator) = array($operator, '='); From e3393d306ae63a88bd67ef476651d951dada4b56 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 21 Jun 2014 13:02:38 -0500 Subject: [PATCH 269/577] Return. --- Query/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index ab7da690a..3cb730d85 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -392,6 +392,8 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { $this->where($innerKey, '=', $innerValue, $boolean); } + + return $this; } // Here we will make some assumptions about the operator. If only 2 values are From 22b1758cea97bbbf9b4d866f2613c7ee9d8f7c3f Mon Sep 17 00:00:00 2001 From: Suhayb El Wardany Date: Tue, 24 Jun 2014 04:44:58 +0200 Subject: [PATCH 270/577] return void if nothing was updated on the model Signed-off-by: Suhayb El Wardany --- Eloquent/Model.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 03951762c..962717edf 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1414,7 +1414,7 @@ protected function finishSave(array $options) * Perform a model update operation. * * @param \Illuminate\Database\Eloquent\Builder $query - * @return bool + * @return bool|null */ protected function performUpdate(Builder $query) { @@ -1449,11 +1449,9 @@ protected function performUpdate(Builder $query) $this->fireModelEvent('updated', false); } - + return true; } - - return false; } /** From dc21ee26c740710a944b1572673a0187d36b01fa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 23 Jun 2014 21:54:09 -0500 Subject: [PATCH 271/577] Fix bug in matching of eager loading in HasManyThrough. --- Eloquent/Relations/HasManyThrough.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 013df2e2f..fd91a37b1 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -168,7 +168,7 @@ protected function buildDictionary(Collection $results) { $dictionary = array(); - $foreign = $this->farParent->getForeignKey(); + $foreign = $this->firstKey; // First we will create a dictionary of models keyed by the foreign key of the // relationship as this will allow us to quickly access all of the related From 7fdeb2958ff94d71240d21da517a50a07cb62ebd Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Tue, 24 Jun 2014 16:59:06 -0400 Subject: [PATCH 272/577] Use nested where for where arrays --- Query/Builder.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 3cb730d85..03e766209 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -385,13 +385,17 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { // If the column is an array, we will assume it is an array of key-value pairs // and can add them each as a where clause. We will maintain the boolean we - // received when the method was called and pass it onto the other wheres. + // received when the method was called and pass it into the nested where. if (is_array($column)) { - foreach ($column as $innerKey => $innerValue) + $this->whereNested(function($query) use($column) { - $this->where($innerKey, '=', $innerValue, $boolean); - } + foreach ($column as $key => $value) + { + $query->where($key, '=', $value); + } + + }, $boolean); return $this; } From 7cc67be3640dcaf3fdf3665dce6fa3f2464b7d8a Mon Sep 17 00:00:00 2001 From: Jon Watson Date: Wed, 25 Jun 2014 20:50:23 +0000 Subject: [PATCH 273/577] Database\Query\Builder::groupBy() now accepts arrays as arguments Also added unit tests. --- Query/Builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 3cb730d85..4005cdc3d 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -973,7 +973,10 @@ protected function addDynamic($segment, $connector, $parameters, $index) */ public function groupBy() { - $this->groups = array_merge((array) $this->groups, func_get_args()); + foreach(func_get_args() AS $arg) + { + $this->groups = array_merge((array) $this->groups, ((is_array($arg)) ? $arg:[$arg])); + } return $this; } From 6e01a1d1ceb11055905504babea85010821982b0 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 25 Jun 2014 21:19:27 -0400 Subject: [PATCH 274/577] Abolish Model::firstByAttributes --- Eloquent/Model.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9f6537d6d..5d2fb4b56 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -534,7 +534,7 @@ public static function create(array $attributes) */ public static function firstOrCreate(array $attributes) { - if ( ! is_null($instance = static::firstByAttributes($attributes))) + if ( ! is_null($instance = static::where($attributes)->first())) { return $instance; } @@ -550,7 +550,7 @@ public static function firstOrCreate(array $attributes) */ public static function firstOrNew(array $attributes) { - if ( ! is_null($instance = static::firstByAttributes($attributes))) + if ( ! is_null($instance = static::where($attributes)->first())) { return $instance; } @@ -582,14 +582,7 @@ public static function updateOrCreate(array $attributes, array $values = array() */ protected static function firstByAttributes($attributes) { - $query = static::query(); - - foreach ($attributes as $key => $value) - { - $query->where($key, $value); - } - - return $query->first() ?: null; + return static::where($attributes)->first(); } /** @@ -1441,7 +1434,7 @@ protected function performUpdate(Builder $query) $this->fireModelEvent('updated', false); } - + return true; } From 64cb4bb33249b691e9bad5ffd9afbcf0a1ab6054 Mon Sep 17 00:00:00 2001 From: Jon Watson Date: Thu, 26 Jun 2014 06:40:36 +0000 Subject: [PATCH 275/577] Lowercase AS => as per laravel convention. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 4005cdc3d..40d62b568 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -973,7 +973,7 @@ protected function addDynamic($segment, $connector, $parameters, $index) */ public function groupBy() { - foreach(func_get_args() AS $arg) + foreach(func_get_args() as $arg) { $this->groups = array_merge((array) $this->groups, ((is_array($arg)) ? $arg:[$arg])); } From 3d18f99c4754d7c73600f917b0f1f2cd56efe81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Fri, 27 Jun 2014 19:22:02 +0800 Subject: [PATCH 276/577] Fix spacing. --- Query/Builder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 3cb730d85..f9d163500 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1006,10 +1006,10 @@ public function having($column, $operator = null, $value = null, $boolean = 'and * @param string $value * @return \Illuminate\Database\Query\Builder|static */ - public function orHaving($column, $operator = null, $value = null) - { - return $this->having($column, $operator, $value, 'or'); - } + public function orHaving($column, $operator = null, $value = null) + { + return $this->having($column, $operator, $value, 'or'); + } /** * Add a raw having clause to the query. From 279461faf30d2589b26a278a1cf6e852709f85a7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 09:18:20 -0500 Subject: [PATCH 277/577] Return true if update is successful, whether anything was updated or not. --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 36de13c53..98a11ce9d 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1434,9 +1434,9 @@ protected function performUpdate(Builder $query) $this->fireModelEvent('updated', false); } - - return true; } + + return true; } /** From 652b2d02e72af6a63f5982ad9aa9f386c33167d7 Mon Sep 17 00:00:00 2001 From: Mattia Trapani Date: Fri, 27 Jun 2014 16:52:26 +0200 Subject: [PATCH 278/577] No need to call get_class twice --- Eloquent/Model.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b69e27e3a..125547882 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -256,9 +256,11 @@ public function __construct(array $attributes = array()) */ protected function bootIfNotBooted() { - if ( ! isset(static::$booted[get_class($this)])) + $class = get_class($this); + + if ( ! isset(static::$booted[$class])) { - static::$booted[get_class($this)] = true; + static::$booted[$class] = true; $this->fireModelEvent('booting', false); @@ -2860,7 +2862,7 @@ public function getMutatedAttributes() if (isset(static::$mutatorCache[$class])) { - return static::$mutatorCache[get_class($this)]; + return static::$mutatorCache[$class]; } return array(); From 3c9a92be6d0f278750ae2d10ea62843a0baa0e10 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 10:04:54 -0500 Subject: [PATCH 279/577] Fix formatting. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index d55617b4f..ddb23a894 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -975,7 +975,7 @@ public function groupBy() { foreach(func_get_args() as $arg) { - $this->groups = array_merge((array) $this->groups, ((is_array($arg)) ? $arg:[$arg])); + $this->groups = array_merge((array) $this->groups, is_array($arg) ? $arg : [$arg]); } return $this; From f7e3bac7b4b4f140b6f83265ef0130a0f01d296c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 10:37:51 -0500 Subject: [PATCH 280/577] Add space. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index c2e07285f..818ef6cb8 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -388,7 +388,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' // received when the method was called and pass it into the nested where. if (is_array($column)) { - $this->whereNested(function($query) use($column) + $this->whereNested(function($query) use ($column) { foreach ($column as $key => $value) { From a9b317a6a0910a82865d391ac37de242e6b6d312 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 10:38:11 -0500 Subject: [PATCH 281/577] Fix spacing. --- Query/Builder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 818ef6cb8..c46a2defa 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -394,7 +394,6 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' { $query->where($key, '=', $value); } - }, $boolean); return $this; From 2bc6eb500e9e3aa639891dd54d8ca35394edcdc9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 10:38:29 -0500 Subject: [PATCH 282/577] Fix return. --- Query/Builder.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index c46a2defa..1a04291ce 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -388,15 +388,13 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' // received when the method was called and pass it into the nested where. if (is_array($column)) { - $this->whereNested(function($query) use ($column) + return $this->whereNested(function($query) use ($column) { foreach ($column as $key => $value) { $query->where($key, '=', $value); } }, $boolean); - - return $this; } // Here we will make some assumptions about the operator. If only 2 values are From 8e49306ac152919cf25313d1010f20d7b7a8f3c2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 15:29:56 -0500 Subject: [PATCH 283/577] Fix spacing. --- Schema/Grammars/MySqlGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 9dcef37cb..bce1db29f 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -578,7 +578,7 @@ protected function modifyComment(Blueprint $blueprint, Fluent $column) { if ( ! is_null($column->comment)) { - return ' comment "' . $column->comment . '"'; + return ' comment "'.$column->comment.'"'; } } From 529f949e5655fdfcde9116de05c77994d43428fd Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 27 Jun 2014 16:47:55 -0400 Subject: [PATCH 284/577] Not passing anything to getDictionary --- Eloquent/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 48e751cb0..740b9e8b6 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -202,7 +202,7 @@ public function unique() */ public function only($keys) { - $dictionary = array_only($this->getDictionary($this), $keys); + $dictionary = array_only($this->getDictionary(), $keys); return new static(array_values($dictionary)); } @@ -215,7 +215,7 @@ public function only($keys) */ public function except($keys) { - $dictionary = array_except($this->getDictionary($this), $keys); + $dictionary = array_except($this->getDictionary(), $keys); return new static(array_values($dictionary)); } From 12f5354f9b693ee558630d13698f0a0a408bca7b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jun 2014 16:11:04 -0500 Subject: [PATCH 285/577] Fix spacing. --- Eloquent/SoftDeletingTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index 1a23149ea..6538b9ab0 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -85,6 +85,7 @@ public function restore() // developer will do anything they need to after a restore operation is // totally finished. Then we will return the result of the save call. $this->exists = true; + $result = $this->save(); $this->fireModelEvent('restored', false); From 3b6e13b0ca5229fab8c936dc786fe90fdeeab36e Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 27 Jun 2014 17:15:36 -0400 Subject: [PATCH 286/577] Fix DocBlock and variable names --- Eloquent/Collection.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 740b9e8b6..d303d6d18 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -73,7 +73,7 @@ public function contains($key) * Fetch a nested element of the collection. * * @param string $key - * @return \Illuminate\Support\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public function fetch($key) { @@ -121,14 +121,14 @@ public function modelKeys() /** * Merge the collection with the given items. * - * @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items - * @return \Illuminate\Support\Collection + * @param \ArrayAccess|array $items + * @return \Illuminate\Database\Eloquent\Collection */ - public function merge($collection) + public function merge($items) { $dictionary = $this->getDictionary(); - foreach ($collection as $item) + foreach ($items as $item) { $dictionary[$item->getKey()] = $item; } @@ -139,14 +139,14 @@ public function merge($collection) /** * Diff the collection with the given items. * - * @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items - * @return \Illuminate\Support\Collection + * @param \ArrayAccess|array $items + * @return \Illuminate\Database\Eloquent\Collection */ - public function diff($collection) + public function diff($items) { $diff = new static; - $dictionary = $this->getDictionary($collection); + $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { @@ -162,14 +162,14 @@ public function diff($collection) /** * Intersect the collection with the given items. * - * @param \Illuminate\Support\Collection|\Illuminate\Support\Contracts\ArrayableInterface|array $items - * @return \Illuminate\Support\Collection + * @param \ArrayAccess|array $items + * @return \Illuminate\Database\Eloquent\Collection */ - public function intersect($collection) + public function intersect($items) { $intersect = new static; - $dictionary = $this->getDictionary($collection); + $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { @@ -185,7 +185,7 @@ public function intersect($collection) /** * Return only unique items from the collection. * - * @return \Illuminate\Support\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public function unique() { @@ -198,7 +198,7 @@ public function unique() * Returns only the models from the collection with the specified keys. * * @param mixed $keys - * @return \Illuminate\Support\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public function only($keys) { @@ -211,7 +211,7 @@ public function only($keys) * Returns all models in the collection except the models with specified keys. * * @param mixed $keys - * @return \Illuminate\Support\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public function except($keys) { @@ -223,16 +223,16 @@ public function except($keys) /** * Get a dictionary keyed by primary keys. * - * @param \Illuminate\Support\Collection $collection + * @param \ArrayAccess|array $items * @return array */ - public function getDictionary($collection = null) + public function getDictionary($items = null) { - $collection = $collection ?: $this; + $items = is_null($items) ? $this->items : $items; $dictionary = array(); - foreach ($collection as $value) + foreach ($items as $value) { $dictionary[$value->getKey()] = $value; } From 5c18fde1a4c754f9705c094ec086cec64179c9d4 Mon Sep 17 00:00:00 2001 From: FractalizeR Date: Sat, 28 Jun 2014 17:18:24 +0400 Subject: [PATCH 287/577] A fix for #4498 and #4684. Eloquent model now boots all used traits, not only those declared in current class only. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 746e191c0..048f26d7a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -304,7 +304,7 @@ protected static function boot() */ protected static function bootTraits() { - foreach (class_uses(get_called_class()) as $trait) + foreach (class_uses_deep(get_called_class()) as $trait) { if (method_exists(get_called_class(), $method = 'boot'.class_basename($trait))) { From 35d47733b72203b5bb6f6b8cd8b0598a6ce2557b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 28 Jun 2014 19:06:59 -0500 Subject: [PATCH 288/577] Cleaning up code. Fixing stuff. Tests. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 048f26d7a..cfc0a66b8 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -304,7 +304,7 @@ protected static function boot() */ protected static function bootTraits() { - foreach (class_uses_deep(get_called_class()) as $trait) + foreach (class_uses_recursive(get_called_class()) as $trait) { if (method_exists(get_called_class(), $method = 'boot'.class_basename($trait))) { From a137701588868971aa82edbf5effeb5bcd5ef93e Mon Sep 17 00:00:00 2001 From: Pavel Nosov Date: Fri, 27 Jun 2014 11:08:49 +0400 Subject: [PATCH 289/577] Return trashed models with morphTo() if told so on non-eager queries (fixes #4870) --- Eloquent/Relations/MorphTo.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index e04d34158..c6f6a51f4 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -161,10 +161,7 @@ protected function getResultsByType($type) $query = $instance->newQuery(); - if ($this->withTrashed && $query->getMacro('withTrashed') !== null) - { - $query = $query->withTrashed(); - } + $query = $this->useWithTrashed($query); return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get(); } @@ -216,7 +213,24 @@ public function withTrashed() { $this->withTrashed = true; + $this->query = $this->useWithTrashed($this->query); + return $this; } + /** + * Return trashed models with query if told so + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function useWithTrashed(Builder $query) + { + if ($this->withTrashed && $query->getMacro('withTrashed') !== null) + { + return $query->withTrashed(); + } + return $query; + } + } From 27c55e7ebf78164760401fbb8059768706df96c4 Mon Sep 17 00:00:00 2001 From: Lionel Gaillard Date: Wed, 22 Jan 2014 19:35:24 +0100 Subject: [PATCH 290/577] Added BelongsTo::dissociate() --- Eloquent/Relations/BelongsTo.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Eloquent/Relations/BelongsTo.php b/Eloquent/Relations/BelongsTo.php index ec78aebac..8cd133761 100755 --- a/Eloquent/Relations/BelongsTo.php +++ b/Eloquent/Relations/BelongsTo.php @@ -207,6 +207,18 @@ public function associate(Model $model) return $this->parent->setRelation($this->relation, $model); } + /** + * Dissociate previously associated model from the given parent. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function dissociate() + { + $this->parent->setAttribute($this->foreignKey, null); + + return $this->parent->setRelation($this->relation, null); + } + /** * Update the parent model on the relationship. * From 3e1ce6670edc3b1caf8de4a0e5090f84aaed7e4d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 30 Jun 2014 10:36:42 +0200 Subject: [PATCH 291/577] Add missing @throw to ELoquent delete docblock --- Eloquent/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index cfc0a66b8..dc00c0464 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1081,6 +1081,7 @@ public static function destroy($ids) * Delete the model from the database. * * @return bool|null + * @throws \Exception */ public function delete() { From 6d0d73f010efc92dacec50e95c2baade34bdb336 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Tue, 1 Jul 2014 12:09:35 +0200 Subject: [PATCH 292/577] Replaces spaces with tabs --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 3d92ac00a..dfd881885 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -74,7 +74,7 @@ public function find($id, $columns = array('*')) { if (is_array($id)) { - return $this->findMany($id, $columns); + return $this->findMany($id, $columns); } $this->query->where($this->model->getKeyName(), '=', $id); From 47db1f8ebd3fa4f7735b3bfb449ca5859e2c5136 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Tue, 1 Jul 2014 15:54:05 -0400 Subject: [PATCH 293/577] Remove unneeded calls to with --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index dc00c0464..d63284bcd 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -829,7 +829,7 @@ public function morphTo($name = null, $type = null, $id = null) $instance = new $class; return new MorphTo( - with($instance)->newQuery(), $this, $id, $instance->getKeyName(), $type, $name + $instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name ); } } @@ -870,7 +870,7 @@ public function hasManyThrough($related, $through, $firstKey = null, $secondKey $secondKey = $secondKey ?: $through->getForeignKey(); - return new HasManyThrough(with(new $related)->newQuery(), $this, $through, $firstKey, $secondKey); + return new HasManyThrough((new $related)->newQuery(), $this, $through, $firstKey, $secondKey); } /** From 4f8a749264b36fe6a7041d7ac879a091dfcf0e1a Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Thu, 3 Jul 2014 14:59:02 -0400 Subject: [PATCH 294/577] [docs] Minor Change to method doc block --- Eloquent/Relations/MorphOneOrMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index a9c28bde4..f4113d44d 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -55,7 +55,7 @@ public function addConstraints() } /** - * Add the constraints for a relationship count query. + * Get the relationship count query. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $parent From a7e501b64eb0c3a22228c2a104485c60de411e48 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 7 Jul 2014 16:45:47 -0400 Subject: [PATCH 295/577] Not passing to model constructor --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d63284bcd..53748a893 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -655,7 +655,7 @@ public static function findOrNew($id, $columns = array('*')) { if ( ! is_null($model = static::find($id, $columns))) return $model; - return new static($columns); + return new static; } /** From d2e367a67fc1fa077a63446fa36692e339ec584f Mon Sep 17 00:00:00 2001 From: alxy Date: Wed, 9 Jul 2014 20:18:09 +0200 Subject: [PATCH 296/577] Fixed a DocBlock ...but also want to mention, that the simplePaginate method doesnt work for me. It uses the regular paginaation view. --- Eloquent/Builder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index dfd881885..c2736e714 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -290,7 +290,6 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) * * This is more efficient on larger data-sets, etc. * - * @param \Illuminate\Pagination\Factory $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator From dea7d409e0de54935ccca1152b99a41f111a000c Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Thu, 10 Jul 2014 22:08:56 -0300 Subject: [PATCH 297/577] Remove unneeded calls to with --- Eloquent/Builder.php | 4 ++-- Eloquent/Model.php | 4 ++-- Eloquent/SoftDeletingTrait.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index dfd881885..76f1473df 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -111,7 +111,7 @@ public function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = $this->find($id, $columns))) return $model; - throw with(new ModelNotFoundException)->setModel(get_class($this->model)); + throw (new ModelNotFoundException)->setModel(get_class($this->model)); } /** @@ -137,7 +137,7 @@ public function firstOrFail($columns = array('*')) { if ( ! is_null($model = $this->first($columns))) return $model; - throw with(new ModelNotFoundException)->setModel(get_class($this->model)); + throw (new ModelNotFoundException)->setModel(get_class($this->model)); } /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 53748a893..d56f186ce 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -594,7 +594,7 @@ protected static function firstByAttributes($attributes) */ public static function query() { - return with(new static)->newQuery(); + return (new static)->newQuery(); } /** @@ -671,7 +671,7 @@ public static function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = static::find($id, $columns))) return $model; - throw with(new ModelNotFoundException)->setModel(get_called_class()); + throw (new ModelNotFoundException)->setModel(get_called_class()); } /** diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index 6538b9ab0..de7f95b8b 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -110,7 +110,7 @@ public function trashed() */ public static function withTrashed() { - return with(new static)->newQueryWithoutScope(new SoftDeletingScope); + return (new static)->newQueryWithoutScope(new SoftDeletingScope); } /** From 6e62581c7378cd56e4c0e8d344c506a3352d960d Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 11 Jul 2014 10:52:42 +0200 Subject: [PATCH 298/577] fixes #5020 pagination issues on HasManyThrough returing intermediate table results as well --- Eloquent/Relations/HasManyThrough.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index fd91a37b1..bf5b177d2 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -252,4 +252,20 @@ public function getHasCompareKey() return $this->farParent->getQualifiedKeyName(); } + + /** + * Get a paginator for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Pagination\Paginator + */ + public function paginate($perPage = null, $columns = array('*')) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + $pager = $this->query->paginate($perPage, $columns); + + return $pager; + } } From f5b2f4817f44d1d1dee63d9bc974d10fe351b2cf Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Fri, 11 Jul 2014 11:27:25 -0300 Subject: [PATCH 299/577] Added some typehints and minor docblock fixes --- DatabaseManager.php | 2 +- Eloquent/Builder.php | 2 +- Query/Builder.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 01ed3f627..d426f24cd 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -216,7 +216,7 @@ public function setDefaultConnection($name) * @param callable $resolver * @return void */ - public function extend($name, $resolver) + public function extend($name, callable $resolver) { $this->extensions[$name] = $resolver; } diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 76f1473df..e14c40836 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -181,7 +181,7 @@ public function pluck($column) * @param callable $callback * @return void */ - public function chunk($count, $callback) + public function chunk($count, callable $callback) { $results = $this->forPage($page = 1, $count)->get(); diff --git a/Query/Builder.php b/Query/Builder.php index 1a04291ce..73e38b766 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1454,7 +1454,7 @@ protected function getCacheCallback($columns) * @param callable $callback * @return void */ - public function chunk($count, $callback) + public function chunk($count, callable $callback) { $results = $this->forPage($page = 1, $count)->get(); From 16493779f0b731983aafd9471b48d10cfb5541ed Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Jul 2014 14:05:52 -0500 Subject: [PATCH 300/577] Method order. --- Eloquent/Relations/HasManyThrough.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index bf5b177d2..f0885030c 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -232,6 +232,22 @@ protected function getSelectColumns(array $columns = array('*')) return array_merge($columns, array($this->parent->getTable().'.'.$this->firstKey)); } + /** + * Get a paginator for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Pagination\Paginator + */ + public function paginate($perPage = null, $columns = array('*')) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + $pager = $this->query->paginate($perPage, $columns); + + return $pager; + } + /** * Get the key name of the parent model. * @@ -252,20 +268,4 @@ public function getHasCompareKey() return $this->farParent->getQualifiedKeyName(); } - - /** - * Get a paginator for the "select" statement. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function paginate($perPage = null, $columns = array('*')) - { - $this->query->addSelect($this->getSelectColumns($columns)); - - $pager = $this->query->paginate($perPage, $columns); - - return $pager; - } } From 3592caac29c119a55147d1526efffe39b1bb46fe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Jul 2014 15:27:45 -0500 Subject: [PATCH 301/577] Make appends respect visible and hidden. --- Eloquent/Model.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d56f186ce..ea9a42011 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2189,7 +2189,7 @@ public function attributesToArray() // Here we will grab all of the appended, calculated attributes to this model // as these attributes are not really in the attributes array, but are run // when we need to array or JSON the model for convenience to the coder. - foreach ($this->appends as $key) + foreach ($this->getArrayableAppends() as $key) { $attributes[$key] = $this->mutateAttributeForArray($key, null); } @@ -2207,6 +2207,23 @@ protected function getArrayableAttributes() return $this->getArrayableItems($this->attributes); } + /** + * Get all of the appendable values that are arrayable. + * + * @return array + */ + protected function getArrayableAppends() + { + if (count($this->appends) > 0) + { + return $this->getArrayableItems( + array_combine($this->appends, $this->appends) + ); + } + + return []; + } + /** * Get the model's relationships in array form. * From a56cc61666674b397bc732f5beb545747610a806 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 11 Jul 2014 16:34:00 -0400 Subject: [PATCH 302/577] Early return --- Eloquent/Model.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ea9a42011..788e34514 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2214,14 +2214,11 @@ protected function getArrayableAttributes() */ protected function getArrayableAppends() { - if (count($this->appends) > 0) - { - return $this->getArrayableItems( - array_combine($this->appends, $this->appends) - ); - } + if ( ! count($this->appends)) return []; - return []; + return $this->getArrayableItems( + array_combine($this->appends, $this->appends) + ); } /** From c6652a77478852dfe42551743aec1b6ee2b8c8fb Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 11 Jul 2014 02:00:50 +0200 Subject: [PATCH 303/577] Update replicate to handles timestamps --- Eloquent/Model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ea9a42011..2b4f00cb3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2593,7 +2593,13 @@ protected function getDateFormat() */ public function replicate() { - $attributes = array_except($this->attributes, array($this->getKeyName())); + $except = [ + $this->getKeyName(), + $this->getCreatedAtColumn(), + $this->getUpdatedAtColumn(), + ]; + + $attributes = array_except($this->attributes, $except); with($instance = new static)->setRawAttributes($attributes); From 7af2b7615d752d2d8868181051a57b9ff1a9a26b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 12 Jul 2014 12:26:04 -0500 Subject: [PATCH 304/577] Allow you to pass an array of columns to not replicate. --- Eloquent/Model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d66bb1764..03a167b8e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2586,11 +2586,12 @@ protected function getDateFormat() /** * Clone the model into a new, non-existing instance. * + * @param array $except * @return \Illuminate\Database\Eloquent\Model */ - public function replicate() + public function replicate(array $except = null) { - $except = [ + $except = $except ?: [ $this->getKeyName(), $this->getCreatedAtColumn(), $this->getUpdatedAtColumn(), From bff7fe764aca2c8763843028a80878810c7d9e20 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 12 Jul 2014 12:29:01 -0500 Subject: [PATCH 305/577] Default values. --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 03a167b8e..f914980f0 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2589,9 +2589,9 @@ protected function getDateFormat() * @param array $except * @return \Illuminate\Database\Eloquent\Model */ - public function replicate(array $except = null) + public function replicate(array $except = []) { - $except = $except ?: [ + $except = count($except) > 0 ? $except : [ $this->getKeyName(), $this->getCreatedAtColumn(), $this->getUpdatedAtColumn(), From 4f8d43b603aac3daecd44b93c9144782df7c83d9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 12 Jul 2014 12:38:21 -0500 Subject: [PATCH 306/577] Tests, fix method. --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index f914980f0..03a167b8e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2589,9 +2589,9 @@ protected function getDateFormat() * @param array $except * @return \Illuminate\Database\Eloquent\Model */ - public function replicate(array $except = []) + public function replicate(array $except = null) { - $except = count($except) > 0 ? $except : [ + $except = $except ?: [ $this->getKeyName(), $this->getCreatedAtColumn(), $this->getUpdatedAtColumn(), From 138486d665af426c4b79eea2d914835280b12cb3 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Sun, 13 Jul 2014 12:58:25 +1000 Subject: [PATCH 307/577] Add ability to add and remove observable events --- Eloquent/Model.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 788e34514..2945714e4 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1261,6 +1261,54 @@ public function getObservableEvents() ); } + /** + * Set the observable event names. + * + * @return void + */ + public function setObservableEvents(array $observables) + { + $this->observables = $observables; + } + + /** + * Add an observable event name. + * + * @param mixed $observables + * @return void + */ + public function addObservableEvents($observables) + { + $observables = is_array($observables) ? $observables : func_get_args(); + + foreach ($observables as $observable) + { + if ( ! in_array($observable, $this->observables)) + { + $this->observables[] = $observable; + } + } + } + + /** + * Remove an observable event name. + * + * @param mixed $observables + * @return void + */ + public function removeObservableEvents($observables) + { + $observables = is_array($observables) ? $observables : func_get_args(); + + foreach ($observables as $observable) + { + if ($index = array_search($observable, $this->observables) !== false) + { + unset($this->observables[$index]); + } + } + } + /** * Increment a column's value by a given amount. * From 3c44d44a74af0855ee7635af034f306c50e26879 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Sun, 13 Jul 2014 19:37:24 +1000 Subject: [PATCH 308/577] Additional tests and bugfix --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2945714e4..433b44eff 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1302,10 +1302,10 @@ public function removeObservableEvents($observables) foreach ($observables as $observable) { - if ($index = array_search($observable, $this->observables) !== false) + if (($index = array_search($observable, $this->observables)) !== false) { unset($this->observables[$index]); - } + } } } From 2a344ade1ad219f5d0282a9150165decdbfc84d0 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 14 Jul 2014 12:18:37 +0100 Subject: [PATCH 309/577] Database docblock fixes --- Connection.php | 12 ++++++------ ConnectionInterface.php | 4 ++-- Eloquent/Model.php | 4 ++-- Migrations/MigrationCreator.php | 2 +- Schema/Blueprint.php | 2 +- Schema/Builder.php | 12 ++++++------ SqlServerConnection.php | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Connection.php b/Connection.php index d5768d60f..194fb2d56 100755 --- a/Connection.php +++ b/Connection.php @@ -409,7 +409,7 @@ public function prepareBindings(array $bindings) /** * Execute a Closure within a transaction. * - * @param Closure $callback + * @param \Closure $callback * @return mixed * * @throws \Exception @@ -506,7 +506,7 @@ public function transactionLevel() /** * Execute the given callback in "dry run" mode. * - * @param Closure $callback + * @param \Closure $callback * @return array */ public function pretend(Closure $callback) @@ -528,9 +528,9 @@ public function pretend(Closure $callback) /** * Run a SQL statement and log its execution context. * - * @param string $query - * @param array $bindings - * @param Closure $callback + * @param string $query + * @param array $bindings + * @param \Closure $callback * @return mixed * * @throws QueryException @@ -588,7 +588,7 @@ public function logQuery($query, $bindings, $time = null) /** * Register a database query listener with the connection. * - * @param Closure $callback + * @param \Closure $callback * @return void */ public function listen(Closure $callback) diff --git a/ConnectionInterface.php b/ConnectionInterface.php index a41f2bb16..48d69b334 100755 --- a/ConnectionInterface.php +++ b/ConnectionInterface.php @@ -102,7 +102,7 @@ public function prepareBindings(array $bindings); /** * Execute a Closure within a transaction. * - * @param Closure $callback + * @param \Closure $callback * @return mixed * * @throws \Exception @@ -140,7 +140,7 @@ public function transactionLevel(); /** * Execute the given callback in "dry run" mode. * - * @param Closure $callback + * @param \Closure $callback * @return array */ public function pretend(Closure $callback); diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 03a167b8e..9150ec12b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -563,8 +563,8 @@ public static function firstOrNew(array $attributes) /** * Create or update a record matching the attributes, and fill it with values. * - * @param array $attributes - * @param array $values + * @param array $attributes + * @param array $values * @return \Illuminate\Database\Eloquent\Model */ public static function updateOrCreate(array $attributes, array $values = array()) diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index 1b6460e89..d709b3e37 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -118,7 +118,7 @@ protected function firePostCreateHooks() /** * Register a post migration create hook. * - * @param Closure $callback + * @param \Closure $callback * @return void */ public function afterCreate(Closure $callback) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 8d660c630..232d1f982 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -39,7 +39,7 @@ class Blueprint { * Create a new schema blueprint. * * @param string $table - * @param Closure $callback + * @param \Closure $callback * @return void */ public function __construct($table, Closure $callback = null) diff --git a/Schema/Builder.php b/Schema/Builder.php index 43891d6c1..a436ca914 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -85,8 +85,8 @@ public function getColumnListing($table) /** * Modify a table on the schema. * - * @param string $table - * @param Closure $callback + * @param string $table + * @param \Closure $callback * @return \Illuminate\Database\Schema\Blueprint */ public function table($table, Closure $callback) @@ -97,8 +97,8 @@ public function table($table, Closure $callback) /** * Create a new table on the schema. * - * @param string $table - * @param Closure $callback + * @param string $table + * @param \Closure $callback * @return \Illuminate\Database\Schema\Blueprint */ public function create($table, Closure $callback) @@ -172,8 +172,8 @@ protected function build(Blueprint $blueprint) /** * Create a new command set with a Closure. * - * @param string $table - * @param Closure $callback + * @param string $table + * @param \Closure $callback * @return \Illuminate\Database\Schema\Blueprint */ protected function createBlueprint($table, Closure $callback = null) diff --git a/SqlServerConnection.php b/SqlServerConnection.php index 47d3ac252..77216c76d 100755 --- a/SqlServerConnection.php +++ b/SqlServerConnection.php @@ -11,7 +11,7 @@ class SqlServerConnection extends Connection { /** * Execute a Closure within a transaction. * - * @param Closure $callback + * @param \Closure $callback * @return mixed * * @throws \Exception From 4b0d758beea7fe82e46a2510fd3bc157e57c285a Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Tue, 15 Jul 2014 07:39:58 +0200 Subject: [PATCH 310/577] Remove duplicate EOL --- Connectors/PostgresConnector.php | 1 - Schema/Grammars/SqlServerGrammar.php | 1 - 2 files changed, 2 deletions(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 8a2ff23ec..ed2050026 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -16,7 +16,6 @@ class PostgresConnector extends Connector implements ConnectorInterface { PDO::ATTR_STRINGIFY_FETCHES => false, ); - /** * Establish a database connection. * diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 751969c0a..79042771b 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -231,7 +231,6 @@ protected function typeChar(Fluent $column) return "nchar({$column->length})"; } - /** * Create the column definition for a string type. * From 2c6c22e85b037efde7bc1792f7bf29a285c10b3f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 15 Jul 2014 11:07:40 +0100 Subject: [PATCH 311/577] Fixed throws docs --- Query/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index 73e38b766..b67c1ed0d 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -2030,6 +2030,8 @@ public function setBindings(array $bindings, $type = 'where') * @param mixed $value * @param string $type * @return \Illuminate\Database\Query\Builder + * + * @throws \InvalidArgumentException */ public function addBinding($value, $type = 'where') { From e402dba0a5d132a1bb157c99190c270c417a4d8c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 15 Jul 2014 12:01:16 +0100 Subject: [PATCH 312/577] Fixed db docblocks --- Connection.php | 12 ++++++------ Connectors/ConnectionFactory.php | 12 ++++++------ Eloquent/Relations/BelongsToMany.php | 5 ++++- Eloquent/Relations/HasManyThrough.php | 1 + Eloquent/Relations/HasOneOrMany.php | 1 + Eloquent/Relations/MorphOneOrMany.php | 1 - Eloquent/Relations/MorphToMany.php | 2 +- Migrations/MigrationCreator.php | 1 + Migrations/Migrator.php | 4 +++- Query/Builder.php | 10 +++++----- Query/JoinClause.php | 1 - Schema/Grammars/Grammar.php | 1 + Schema/Grammars/MySqlGrammar.php | 1 - 13 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Connection.php b/Connection.php index 194fb2d56..e4bf824a4 100755 --- a/Connection.php +++ b/Connection.php @@ -123,10 +123,10 @@ class Connection implements ConnectionInterface { /** * Create a new database connection instance. * - * @param PDO $pdo - * @param string $database - * @param string $tablePrefix - * @param array $config + * @param \PDO $pdo + * @param string $database + * @param string $tablePrefix + * @param array $config * @return void */ public function __construct(PDO $pdo, $database = '', $tablePrefix = '', array $config = array()) @@ -687,7 +687,7 @@ public function getReadPdo() /** * Set the PDO connection. * - * @param PDO $pdo + * @param \PDO $pdo * @return \Illuminate\Database\Connection */ public function setPdo(PDO $pdo) @@ -700,7 +700,7 @@ public function setPdo(PDO $pdo) /** * Set the PDO connection used for reading. * - * @param PDO $pdo + * @param \PDO $pdo * @return \Illuminate\Database\Connection */ public function setReadPdo(PDO $pdo) diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index 5d5b233b5..2e63ec6f0 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -116,7 +116,7 @@ protected function getWriteConfig(array $config) /** * Get a read / write level configuration. * - * @param array $config + * @param array $config * @param string $type * @return array */ @@ -197,11 +197,11 @@ public function createConnector(array $config) /** * Create a new connection instance. * - * @param string $driver - * @param PDO $connection - * @param string $database - * @param string $prefix - * @param array $config + * @param string $driver + * @param \PDO $connection + * @param string $database + * @param string $prefix + * @param array $config * @return \Illuminate\Database\Connection * * @throws \InvalidArgumentException diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index eefd51a8d..3532f327b 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -93,7 +93,6 @@ public function wherePivot($column, $operator = null, $value = null, $boolean = * @param string $column * @param string $operator * @param mixed $value - * @param string $boolean * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function orWherePivot($column, $operator = null, $value = null) @@ -289,6 +288,7 @@ public function getRelationCountHash() /** * Set the select clause for the relation query. * + * @param array $columns * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ protected function getSelectColumns(array $columns = array('*')) @@ -710,6 +710,7 @@ public function attach($id, array $attributes = array(), $touch = true) * Create an array of records to insert into the pivot table. * * @param array $ids + * @param array $attributes * @return array */ protected function createAttachRecords($ids, array $attributes) @@ -957,6 +958,8 @@ public function withPivot($columns) /** * Specify that the pivot table has creation and update timestamps. * + * @param mixed $createdAt + * @param mixed $updatedAt * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function withTimestamps($createdAt = null, $updatedAt = null) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index f0885030c..f378ce660 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -220,6 +220,7 @@ public function get($columns = array('*')) /** * Set the select clause for the relation query. * + * @param array $columns * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ protected function getSelectColumns(array $columns = array('*')) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index accd8e21a..87bc4afe5 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -26,6 +26,7 @@ abstract class HasOneOrMany extends Relation { * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent * @param string $foreignKey + * @param string $localKey * @return void */ public function __construct(Builder $query, Model $parent, $foreignKey, $localKey) diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index f4113d44d..9c6ae7e2d 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -27,7 +27,6 @@ abstract class MorphOneOrMany extends HasOneOrMany { * @param string $type * @param string $id * @param string $localKey - * @param string $morphClass * @return void */ public function __construct(Builder $query, Model $parent, $type, $id, $localKey) diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 6d8eeb1e5..3908b4183 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -38,7 +38,7 @@ class MorphToMany extends BelongsToMany { * @param string $foreignKey * @param string $otherKey * @param string $relationName - * @param bool $inverse + * @param bool $inverse * @return void */ public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false) diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index d709b3e37..e62a53130 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -59,6 +59,7 @@ public function create($name, $path, $table = null, $create = false) * Get the migration stub file. * * @param string $table + * @param bool $create * @return string */ protected function getStub($table, $create) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index d41111a3f..10806f5ca 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -236,7 +236,8 @@ public function getMigrationFiles($path) /** * Require in all the migration files in a given path. * - * @param array $files + * @param string $path + * @param array $files * @return void */ public function requireFiles($path, array $files) @@ -248,6 +249,7 @@ public function requireFiles($path, array $files) * Pretend to run the migrations. * * @param object $migration + * @param string $method * @return void */ protected function pretendToRun($migration, $method) diff --git a/Query/Builder.php b/Query/Builder.php index 73e38b766..b72808c01 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -265,11 +265,11 @@ public function from($table) * Add a join clause to the query. * * @param string $table - * @param string $first + * @param string $one * @param string $operator * @param string $two * @param string $type - * @param bool $where + * @param bool $where * @return \Illuminate\Database\Query\Builder|static */ public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false) @@ -303,7 +303,7 @@ public function join($table, $one, $operator = null, $two = null, $type = 'inner * Add a "join where" clause to the query. * * @param string $table - * @param string $first + * @param string $one * @param string $operator * @param string $two * @param string $type @@ -332,7 +332,7 @@ public function leftJoin($table, $first, $operator = null, $second = null) * Add a "join where" clause to the query. * * @param string $table - * @param string $first + * @param string $one * @param string $operator * @param string $two * @return \Illuminate\Database\Query\Builder|static @@ -360,7 +360,7 @@ public function rightJoin($table, $first, $operator = null, $second = null) * Add a "right join where" clause to the query. * * @param string $table - * @param string $first + * @param string $one * @param string $operator * @param string $two * @return \Illuminate\Database\Query\Builder|static diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 76b84c861..dbe79ef9b 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -97,7 +97,6 @@ public function where($first, $operator, $second, $boolean = 'and') * @param string $first * @param string $operator * @param string $second - * @param string $boolean * @return \Illuminate\Database\Query\JoinClause */ public function orWhere($first, $operator, $second) diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index c5c57ccef..531d5793c 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -153,6 +153,7 @@ protected function addModifiers($sql, Blueprint $blueprint, Fluent $column) * Get the primary key command if it exists on the blueprint. * * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param string $name * @return \Illuminate\Support\Fluent|null */ protected function getCommandByName(Blueprint $blueprint, $name) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index bce1db29f..da377ac97 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -33,7 +33,6 @@ public function compileTableExists() /** * Compile the query to determine the list of columns. * - * @param string $table * @return string */ public function compileColumnExists() From fec35c8261e68f5f0978e9e2d133dcf057df524a Mon Sep 17 00:00:00 2001 From: Jarek Tkaczyk Date: Wed, 16 Jul 2014 13:05:45 +0200 Subject: [PATCH 313/577] 4.2-fix-associate-on-morphTo --- Eloquent/Relations/MorphTo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index e04d34158..b9652b5e9 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -104,7 +104,7 @@ public function associate(Model $model) { $this->parent->setAttribute($this->foreignKey, $model->getKey()); - $this->parent->setAttribute($this->morphType, get_class($model)); + $this->parent->setAttribute($this->morphType, $model->getMorphClass()); return $this->parent->setRelation($this->relation, $model); } From 3b7bd86b5570d32072cc3a46d51cb1582143f8fd Mon Sep 17 00:00:00 2001 From: Tim Groeneveld Date: Thu, 17 Jul 2014 18:18:24 +1000 Subject: [PATCH 314/577] Allow chunk to exit when the closure returns false When looping through all of the different rows returned by an SQL statement using a chunk closure, you should be able to specify to Builder that you wish to no longer continue processing chunks by simply returning false inside the closure, without having to exit. --- Query/Builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 65f8e2721..9e2f9940a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1505,7 +1505,10 @@ public function chunk($count, $callback) // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. - call_user_func($callback, $results); + $return = call_user_func($callback, $results); + + if ($return === false) + continue; $page++; From 6b8164cdb172e33960027f2d5d6a3a0b3cbe671c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 16 Jul 2014 11:39:21 +0100 Subject: [PATCH 315/577] Added another missing throws annotation --- Query/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index acc020856..62db15f09 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -2011,6 +2011,8 @@ public function getRawBindings() * @param array $bindings * @param string $type * @return \Illuminate\Database\Query\Builder + * + * @throws \InvalidArgumentException */ public function setBindings(array $bindings, $type = 'where') { From 719335c29c1534c5f1dd80409a2fbf779345463e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Jul 2014 10:16:27 -0500 Subject: [PATCH 316/577] Set incremented value on model. --- Eloquent/Model.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9150ec12b..d35bbc497 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1302,9 +1302,26 @@ protected function incrementOrDecrement($column, $amount, $method) return $query->{$method}($column, $amount); } + $this->incrementOrDecrementAttributeValue($column, $amount, $method); + return $query->where($this->getKeyName(), $this->getKey())->{$method}($column, $amount); } + /** + * Increment the underlying attribute value and sync with original. + * + * @param string $column + * @param int $amount + * @param string $method + * @return void + */ + protected function incrementOrDecrementAttributeValue($column, $amount, $method) + { + $this->{$column} = $this->{$column} + ($method == 'increment' ? $amount : $amount * -1); + + $this->syncOriginalAttribute($column); + } + /** * Update the model in the database. * @@ -2652,6 +2669,19 @@ public function syncOriginal() return $this; } + /** + * Sync a single original attribute with its current value. + * + * @param string $attribute + * @return \Illuminate\Database\Eloquent\Model + */ + public function syncOriginalAttribute($attribute) + { + $this->original[$attribute] = $this->attributes[$attribute]; + + return $this; + } + /** * Determine if the model or a given attribute has been modified. * From 6a5758c55dfd7d9667c5ac5b8ad9b4d609eac22c Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 19 Jul 2014 00:52:39 +0200 Subject: [PATCH 317/577] Remove double if --- Eloquent/Relations/BelongsToMany.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 3532f327b..72b835f05 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -654,12 +654,9 @@ protected function attachNew(array $records, array $current, $touch = true) // Now we'll try to update an existing pivot record with the attributes that were // given to the method. If the model is actually updated we will add it to the // list of updated pivot records so we return them back out to the consumer. - elseif (count($attributes) > 0) + elseif (count($attributes) > 0 && $this->updateExistingPivot($id, $attributes, $touch)) { - if ($this->updateExistingPivot($id, $attributes, $touch)) - { - $changes['updated'][] = (int) $id; - } + $changes['updated'][] = (int) $id; } } return $changes; From e5c8cab2f1af098b3e56c49c2cdb4dee54c33542 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 19 Jul 2014 02:19:21 +0200 Subject: [PATCH 318/577] remove double if --- Eloquent/Model.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d35bbc497..5c0aa9905 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2474,12 +2474,9 @@ public function setAttribute($key, $value) // If an attribute is listed as a "date", we'll convert it from a DateTime // instance into a form proper for storage on the database tables using // the connection grammar's date format. We will auto set the values. - elseif (in_array($key, $this->getDates())) + elseif (in_array($key, $this->getDates()) && $value) { - if ($value) - { - $value = $this->fromDateTime($value); - } + $value = $this->fromDateTime($value); } $this->attributes[$key] = $value; From 49090d689d9edea45c0da9e301184878e20701a1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 18 Jul 2014 20:43:10 -0500 Subject: [PATCH 319/577] Shorten line. --- Eloquent/Relations/BelongsToMany.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 72b835f05..f409cea80 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -654,7 +654,8 @@ protected function attachNew(array $records, array $current, $touch = true) // Now we'll try to update an existing pivot record with the attributes that were // given to the method. If the model is actually updated we will add it to the // list of updated pivot records so we return them back out to the consumer. - elseif (count($attributes) > 0 && $this->updateExistingPivot($id, $attributes, $touch)) + elseif (count($attributes) > 0 && + $this->updateExistingPivot($id, $attributes, $touch)) { $changes['updated'][] = (int) $id; } From 35adb30b2b9e26222e6c0803a5643e86674f13c1 Mon Sep 17 00:00:00 2001 From: crynobone Date: Mon, 21 Jul 2014 07:19:36 +0800 Subject: [PATCH 320/577] Return Illuminate\Support\Fluent when possible, this allow developer to further chain additional command such as ->after() etc. Signed-off-by: crynobone --- Schema/Blueprint.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 232d1f982..06aa96b5a 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -639,11 +639,11 @@ public function timestamps() /** * Add a "deleted at" timestamp for the table. * - * @return void + * @return \Illuminate\Support\Fluent */ public function softDeletes() { - $this->timestamp('deleted_at')->nullable(); + return $this->timestamp('deleted_at')->nullable(); } /** @@ -675,11 +675,11 @@ public function morphs($name) /** * Adds the `remember_token` column to the table. * - * @return void + * @return \Illuminate\Support\Fluent */ public function rememberToken() { - $this->string('remember_token', 100)->nullable(); + return $this->string('remember_token', 100)->nullable(); } /** From 214c66214875d1c7650ca0adb94862e731b816d9 Mon Sep 17 00:00:00 2001 From: crynobone Date: Tue, 15 Jul 2014 13:57:19 +0800 Subject: [PATCH 321/577] Move common method for a CapsuleManager to trait, this would reduce the requirement to produce new CapsuleManager for other component in the future (e.g: laravel/framework#5032) Also remove duplicate "require-dev" component (when already explicitly declare in "require"). Signed-off-by: crynobone --- Capsule/Manager.php | 63 ++------------------------------------------- composer.json | 3 +-- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 6283e3004..7cc277395 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -1,22 +1,17 @@ setupManager(); } - /** - * Setup the IoC container instance. - * - * @param \Illuminate\Container\Container|null $container - * @return void - */ - protected function setupContainer($container) - { - $this->container = $container ?: new Container; - - if ( ! $this->container->bound('config')) - { - $this->container->instance('config', new Fluent); - } - } - /** * Setup the default database configuration options. * @@ -182,16 +154,6 @@ public function setFetchMode($fetchMode) return $this; } - /** - * Make this capsule instance available globally. - * - * @return void - */ - public function setAsGlobal() - { - static::$instance = $this; - } - /** * Get the database manager instance. * @@ -250,27 +212,6 @@ public function setCacheManager(CacheManager $cache) $this->container->instance('cache', $cache); } - /** - * Get the IoC container instance. - * - * @return \Illuminate\Container\Container - */ - public function getContainer() - { - return $this->container; - } - - /** - * Set the IoC container instance. - * - * @param \Illuminate\Container\Container $container - * @return void - */ - public function setContainer(Container $container) - { - $this->container = $container; - } - /** * Dynamically pass methods to the default connection. * diff --git a/composer.json b/composer.json index fa4bd4b19..1c284c01b 100755 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "illuminate/cache": "4.2.*", "illuminate/console": "4.2.*", "illuminate/filesystem": "4.2.*", - "illuminate/pagination": "4.2.*", - "illuminate/support": "4.2.*" + "illuminate/pagination": "4.2.*" }, "autoload": { "psr-0": { From 1aef3b268280b60a9b473c1e122af59638a12a2b Mon Sep 17 00:00:00 2001 From: Tim Groeneveld Date: Tue, 22 Jul 2014 12:04:26 +1000 Subject: [PATCH 322/577] Use break to exit the loop, not continue. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 9e2f9940a..ec9f79057 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1508,7 +1508,7 @@ public function chunk($count, $callback) $return = call_user_func($callback, $results); if ($return === false) - continue; + break; $page++; From 81de2cd685aaec44b7c0dd6ebd25761187d730eb Mon Sep 17 00:00:00 2001 From: Pavel Kirpichyov Date: Tue, 22 Jul 2014 10:47:37 +0300 Subject: [PATCH 323/577] Add an "on where is null" clause to the join --- Query/JoinClause.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Query/JoinClause.php b/Query/JoinClause.php index dbe79ef9b..31cd429ba 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -104,4 +104,16 @@ public function orWhere($first, $operator, $second) return $this->on($first, $operator, $second, 'or', true); } + /** + * Add an "on where is null" clause to the join + * + * @param $first + * @param string $boolean + * @return \Illuminate\Database\Query\JoinClause + */ + public function whereNull($first, $boolean = 'and') + { + return $this->on($first, 'is', new Expression('null'), $boolean, false); + } + } From 24d21ddf44a6179d4e63cec17864d429c179a7e7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 24 Jul 2014 20:41:42 -0500 Subject: [PATCH 324/577] Rename variable. --- Query/JoinClause.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 31cd429ba..db7ab58d3 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -107,13 +107,13 @@ public function orWhere($first, $operator, $second) /** * Add an "on where is null" clause to the join * - * @param $first + * @param $column * @param string $boolean * @return \Illuminate\Database\Query\JoinClause */ - public function whereNull($first, $boolean = 'and') + public function whereNull($column, $boolean = 'and') { - return $this->on($first, 'is', new Expression('null'), $boolean, false); + return $this->on($column, 'is', new Expression('null'), $boolean, false); } } From a0a840c131c496430befe82ce295f28879d91d95 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 27 Jul 2014 15:21:41 +0100 Subject: [PATCH 325/577] Corrected return type on the eloquent model update --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 5c0aa9905..9cad46a59 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1326,7 +1326,7 @@ protected function incrementOrDecrementAttributeValue($column, $amount, $method) * Update the model in the database. * * @param array $attributes - * @return mixed + * @return bool|int */ public function update(array $attributes = array()) { From a5e66aed9f901e0ec26e3a6c684decb4ff5a801f Mon Sep 17 00:00:00 2001 From: Valeriy Trubachev Date: Tue, 29 Jul 2014 14:08:55 -0500 Subject: [PATCH 326/577] Add multiple attribute support to Model::isDirty --- Eloquent/Model.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9cad46a59..727a8d181 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2680,19 +2680,30 @@ public function syncOriginalAttribute($attribute) } /** - * Determine if the model or a given attribute has been modified. + * Determine if the model or given attribute(s) have been modified. * - * @param string|null $attribute + * @param string|array|null $attribute * @return bool */ public function isDirty($attribute = null) { $dirty = $this->getDirty(); + if (func_num_args() > 1) $attribute = func_get_args(); + if (is_null($attribute)) { return count($dirty) > 0; } + elseif (is_array($attribute)) + { + foreach ($attribute as $attr) + { + if (array_key_exists($attr, $dirty)) return true; + } + + return false; + } else { return array_key_exists($attribute, $dirty); From 5b156b5c344571b86449414063ab13b3a4fd3611 Mon Sep 17 00:00:00 2001 From: Theodore Olsen Date: Wed, 30 Jul 2014 08:29:44 -0400 Subject: [PATCH 327/577] [4.2] Fixed empty string in database connection config 'unix_socket' causes system to default to socket connection instead of host connection --- Connectors/MySqlConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index 9ddf18b48..f9518cbf1 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -55,7 +55,7 @@ public function connect(array $config) */ protected function getDsn(array $config) { - return isset($config['unix_socket']) ? $this->getSocketDsn($config) : $this->getHostDsn($config); + return isset($config['unix_socket']) && !empty($config['unix_socket']) ? $this->getSocketDsn($config) : $this->getHostDsn($config); } /** From 31f0ff696c668b32cd99db173db4810f78dec886 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 30 Jul 2014 15:07:16 +0200 Subject: [PATCH 328/577] Missing space in foreach --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 62db15f09..1750a1f17 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -974,7 +974,7 @@ protected function addDynamic($segment, $connector, $parameters, $index) */ public function groupBy() { - foreach(func_get_args() as $arg) + foreach (func_get_args() as $arg) { $this->groups = array_merge((array) $this->groups, is_array($arg) ? $arg : [$arg]); } From 2c1a32ff775c85daae99eae79c4a8b529e7bc545 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 1 Aug 2014 14:29:44 +0200 Subject: [PATCH 329/577] Update phpdocs for better chaining Following the PSR-5 Proposal, chained methods should use `return $this`. New instances should use `return static`. This way, when classes are extended, they refer to the correct class. --- Capsule/Manager.php | 2 +- Connection.php | 4 +- Eloquent/Builder.php | 6 +-- Eloquent/Collection.php | 6 +-- Eloquent/Model.php | 18 ++++---- Eloquent/ModelNotFoundException.php | 2 +- Eloquent/Relations/BelongsToMany.php | 6 +-- Eloquent/Relations/MorphPivot.php | 2 +- Eloquent/Relations/MorphTo.php | 2 +- Eloquent/Relations/MorphToMany.php | 2 +- Eloquent/Relations/Pivot.php | 2 +- Grammar.php | 2 +- Query/Builder.php | 63 ++++++++++++++-------------- Query/JoinClause.php | 2 +- Schema/Blueprint.php | 2 +- Schema/Builder.php | 2 +- Seeder.php | 4 +- 17 files changed, 63 insertions(+), 64 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 6283e3004..374d9c7a2 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -173,7 +173,7 @@ public function bootEloquent() * Set the fetch mode for the database connections. * * @param int $fetchMode - * @return \Illuminate\Database\Capsule\Manager + * @return $this */ public function setFetchMode($fetchMode) { diff --git a/Connection.php b/Connection.php index e4bf824a4..b15374aff 100755 --- a/Connection.php +++ b/Connection.php @@ -688,7 +688,7 @@ public function getReadPdo() * Set the PDO connection. * * @param \PDO $pdo - * @return \Illuminate\Database\Connection + * @return $this */ public function setPdo(PDO $pdo) { @@ -701,7 +701,7 @@ public function setPdo(PDO $pdo) * Set the PDO connection used for reading. * * @param \PDO $pdo - * @return \Illuminate\Database\Connection + * @return $this */ public function setReadPdo(PDO $pdo) { diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index e1e10ec36..74782959f 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -556,7 +556,7 @@ protected function isNested($name, $relation) * @param string $operator * @param mixed $value * @param string $boolean - * @return \Illuminate\Database\Eloquent\Builder|static + * @return $this */ public function where($column, $operator = null, $value = null, $boolean = 'and') { @@ -712,7 +712,7 @@ protected function getHasRelationQuery($relation) * Set the relationships that should be eager loaded. * * @param dynamic $relations - * @return \Illuminate\Database\Eloquent\Builder|static + * @return $this */ public function with($relations) { @@ -855,7 +855,7 @@ public function getModel() * Set a model instance for the model being queried. * * @param \Illuminate\Database\Eloquent\Model $model - * @return \Illuminate\Database\Eloquent\Builder + * @return $this */ public function setModel(Model $model) { diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index d303d6d18..8c41b4dbb 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -28,8 +28,8 @@ public function find($key, $default = null) /** * Load a set of relationships onto the collection. * - * @param dynamic $relations - * @return \Illuminate\Database\Eloquent\Collection + * @param mixed $relations + * @return $this */ public function load($relations) { @@ -49,7 +49,7 @@ public function load($relations) * Add an item to the collection. * * @param mixed $item - * @return \Illuminate\Database\Eloquent\Collection + * @return $this */ public function add($item) { diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9cad46a59..7f9fc4069 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -387,7 +387,7 @@ public static function observe($class) * Fill the model with an array of attributes. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model|static + * @return $this * * @throws MassAssignmentException */ @@ -678,7 +678,7 @@ public static function findOrFail($id, $columns = array('*')) * Eager load relations on the model. * * @param array|string $relations - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function load($relations) { @@ -1990,7 +1990,7 @@ public function getFillable() * Set the fillable attributes for the model. * * @param array $fillable - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function fillable(array $fillable) { @@ -2003,7 +2003,7 @@ public function fillable(array $fillable) * Set the guarded attributes for the model. * * @param array $guarded - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function guard(array $guarded) { @@ -2657,7 +2657,7 @@ public function getOriginal($key = null, $default = null) /** * Sync the original attributes with the current. * - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function syncOriginal() { @@ -2670,7 +2670,7 @@ public function syncOriginal() * Sync a single original attribute with its current value. * * @param string $attribute - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function syncOriginalAttribute($attribute) { @@ -2765,7 +2765,7 @@ public function getRelation($relation) * * @param string $relation * @param mixed $value - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function setRelation($relation, $value) { @@ -2778,7 +2778,7 @@ public function setRelation($relation, $value) * Set the entire relations array on the model. * * @param array $relations - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function setRelations(array $relations) { @@ -2811,7 +2811,7 @@ public function getConnectionName() * Set the connection associated with the model. * * @param string $name - * @return \Illuminate\Database\Eloquent\Model + * @return $this */ public function setConnection($name) { diff --git a/Eloquent/ModelNotFoundException.php b/Eloquent/ModelNotFoundException.php index 2256f1394..db98c25e7 100755 --- a/Eloquent/ModelNotFoundException.php +++ b/Eloquent/ModelNotFoundException.php @@ -13,7 +13,7 @@ class ModelNotFoundException extends \RuntimeException { * Set the affected Eloquent model. * * @param string $model - * @return ModelNotFoundException + * @return $this */ public function setModel($model) { diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index f409cea80..776b38aba 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -327,7 +327,7 @@ protected function getAliasedPivotColumns() * Set the join clause for the relation query. * * @param \Illuminate\Database\Eloquent\Builder|null - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return $this */ protected function setJoin($query = null) { @@ -348,7 +348,7 @@ protected function setJoin($query = null) /** * Set the where clause for the relation query. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return $this */ protected function setWhere() { @@ -942,7 +942,7 @@ public function newExistingPivot(array $attributes = array()) * Set the columns on the pivot table to retrieve. * * @param array $columns - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return $this */ public function withPivot($columns) { diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index ec3c1b873..adcf67de1 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -44,7 +44,7 @@ public function delete() * Set the morph type for the pivot. * * @param string $morphType - * @return \Illuminate\Database\Eloquent\Relations\MorphPivot + * @return $this */ public function setMorphType($morphType) { diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index c6f6a51f4..f2f8f9e51 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -207,7 +207,7 @@ public function getDictionary() /** * Fetch soft-deleted model instances with query * - * @return MorphTo + * @return $this */ public function withTrashed() { diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 3908b4183..671fdc422 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -53,7 +53,7 @@ public function __construct(Builder $query, Model $parent, $name, $table, $forei /** * Set the where clause for the relation query. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return $this */ protected function setWhere() { diff --git a/Eloquent/Relations/Pivot.php b/Eloquent/Relations/Pivot.php index 9645062cd..365477e05 100755 --- a/Eloquent/Relations/Pivot.php +++ b/Eloquent/Relations/Pivot.php @@ -127,7 +127,7 @@ public function getOtherKey() * * @param string $foreignKey * @param string $otherKey - * @return \Illuminate\Database\Eloquent\Relations\Pivot + * @return $this */ public function setPivotKeys($foreignKey, $otherKey) { diff --git a/Grammar.php b/Grammar.php index c67c4951e..153c15223 100755 --- a/Grammar.php +++ b/Grammar.php @@ -167,7 +167,7 @@ public function getTablePrefix() * Set the grammar's table prefix. * * @param string $prefix - * @return \Illuminate\Database\Grammar + * @return $this */ public function setTablePrefix($prefix) { diff --git a/Query/Builder.php b/Query/Builder.php index 1750a1f17..5dc368f89 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -201,7 +201,7 @@ public function __construct(ConnectionInterface $connection, * Set the columns to be selected. * * @param array $columns - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function select($columns = array('*')) { @@ -225,7 +225,7 @@ public function selectRaw($expression) * Add a new select column to the query. * * @param mixed $column - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function addSelect($column) { @@ -239,7 +239,7 @@ public function addSelect($column) /** * Force the query to only return distinct results. * - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function distinct() { @@ -252,7 +252,7 @@ public function distinct() * Set the table which the query is targeting. * * @param string $table - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function from($table) { @@ -270,7 +270,7 @@ public function from($table) * @param string $two * @param string $type * @param bool $where - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false) { @@ -377,7 +377,7 @@ public function rightJoinWhere($table, $one, $operator, $two) * @param string $operator * @param mixed $value * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this * * @throws \InvalidArgumentException */ @@ -489,7 +489,7 @@ protected function invalidOperatorAndValue($operator, $value) * @param string $sql * @param array $bindings * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function whereRaw($sql, array $bindings = array(), $boolean = 'and') { @@ -521,7 +521,7 @@ public function orWhereRaw($sql, array $bindings = array()) * @param array $values * @param string $boolean * @param bool $not - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function whereBetween($column, array $values, $boolean = 'and', $not = false) { @@ -597,7 +597,7 @@ public function whereNested(Closure $callback, $boolean = 'and') * * @param \Illuminate\Database\Query\Builder|static $query * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function addNestedWhereQuery($query, $boolean = 'and') { @@ -620,7 +620,7 @@ public function addNestedWhereQuery($query, $boolean = 'and') * @param string $operator * @param \Closure $callback * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ protected function whereSub($column, $operator, Closure $callback, $boolean) { @@ -646,7 +646,7 @@ protected function whereSub($column, $operator, Closure $callback, $boolean) * @param \Closure $callback * @param string $boolean * @param bool $not - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function whereExists(Closure $callback, $boolean = 'and', $not = false) { @@ -708,7 +708,7 @@ public function orWhereNotExists(Closure $callback) * @param mixed $values * @param string $boolean * @param bool $not - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function whereIn($column, $values, $boolean = 'and', $not = false) { @@ -773,7 +773,7 @@ public function orWhereNotIn($column, $values) * @param \Closure $callback * @param string $boolean * @param bool $not - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ protected function whereInSub($column, Closure $callback, $boolean, $not) { @@ -797,7 +797,7 @@ protected function whereInSub($column, Closure $callback, $boolean, $not) * @param string $column * @param string $boolean * @param bool $not - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function whereNull($column, $boolean = 'and', $not = false) { @@ -892,7 +892,7 @@ public function whereYear($column, $operator, $value, $boolean = 'and') * @param string $operator * @param int $value * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and') { @@ -908,7 +908,7 @@ protected function addDateBasedWhere($type, $column, $operator, $value, $boolean * * @param string $method * @param string $parameters - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function dynamicWhere($method, $parameters) { @@ -969,8 +969,7 @@ protected function addDynamic($segment, $connector, $parameters, $index) /** * Add a "group by" clause to the query. * - * @param dynamic $columns - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function groupBy() { @@ -989,7 +988,7 @@ public function groupBy() * @param string $operator * @param string $value * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function having($column, $operator = null, $value = null, $boolean = 'and') { @@ -1021,7 +1020,7 @@ public function orHaving($column, $operator = null, $value = null) * @param string $sql * @param array $bindings * @param string $boolean - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function havingRaw($sql, array $bindings = array(), $boolean = 'and') { @@ -1051,7 +1050,7 @@ public function orHavingRaw($sql, array $bindings = array()) * * @param string $column * @param string $direction - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function orderBy($column, $direction = 'asc') { @@ -1089,7 +1088,7 @@ public function oldest($column = 'created_at') * * @param string $sql * @param array $bindings - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function orderByRaw($sql, $bindings = array()) { @@ -1106,7 +1105,7 @@ public function orderByRaw($sql, $bindings = array()) * Set the "offset" value of the query. * * @param int $value - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function offset($value) { @@ -1130,7 +1129,7 @@ public function skip($value) * Set the "limit" value of the query. * * @param int $value - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function limit($value) { @@ -1195,8 +1194,8 @@ public function unionAll($query) /** * Lock the selected rows in the table. * - * @param bool $update - * @return \Illuminate\Database\Query\Builder + * @param bool $value + * @return $this */ public function lock($value = true) { @@ -1240,7 +1239,7 @@ public function toSql() * * @param \DateTime|int $minutes * @param string $key - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function remember($minutes, $key = null) { @@ -1264,7 +1263,7 @@ public function rememberForever($key = null) * Indicate that the results, if cached, should use the given cache tags. * * @param array|dynamic $cacheTags - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function cacheTags($cacheTags) { @@ -1277,7 +1276,7 @@ public function cacheTags($cacheTags) * Indicate that the results, if cached, should use the given cache driver. * * @param string $cacheDriver - * @return \Illuminate\Database\Query\Builder|static + * @return $this */ public function cacheDriver($cacheDriver) { @@ -2010,7 +2009,7 @@ public function getRawBindings() * * @param array $bindings * @param string $type - * @return \Illuminate\Database\Query\Builder + * @return $this * * @throws \InvalidArgumentException */ @@ -2031,7 +2030,7 @@ public function setBindings(array $bindings, $type = 'where') * * @param mixed $value * @param string $type - * @return \Illuminate\Database\Query\Builder + * @return $this * * @throws \InvalidArgumentException */ @@ -2058,7 +2057,7 @@ public function addBinding($value, $type = 'where') * Merge an array of bindings into our bindings. * * @param \Illuminate\Database\Query\Builder $query - * @return \Illuminate\Database\Query\Builder + * @return $this */ public function mergeBindings(Builder $query) { diff --git a/Query/JoinClause.php b/Query/JoinClause.php index db7ab58d3..837f4635c 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -53,7 +53,7 @@ public function __construct(Builder $query, $type, $table) * @param string $second * @param string $boolean * @param bool $where - * @return \Illuminate\Database\Query\JoinClause + * @return $this */ public function on($first, $operator, $second, $boolean = 'and', $where = false) { diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 06aa96b5a..22f82ca31 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -765,7 +765,7 @@ protected function addColumn($type, $name, array $parameters = array()) * Remove a column from the schema blueprint. * * @param string $name - * @return \Illuminate\Database\Schema\Blueprint + * @return $this */ public function removeColumn($name) { diff --git a/Schema/Builder.php b/Schema/Builder.php index a436ca914..c40c2e23a 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -202,7 +202,7 @@ public function getConnection() * Set the database connection instance. * * @param \Illuminate\Database\Connection - * @return \Illuminate\Database\Schema\Builder + * @return $this */ public function setConnection(Connection $connection) { diff --git a/Seeder.php b/Seeder.php index 547cfb969..9074dce98 100755 --- a/Seeder.php +++ b/Seeder.php @@ -73,7 +73,7 @@ protected function resolve($class) * Set the IoC container instance. * * @param \Illuminate\Container\Container $container - * @return \Illuminate\Database\Seeder + * @return $this */ public function setContainer(Container $container) { @@ -86,7 +86,7 @@ public function setContainer(Container $container) * Set the console command instance. * * @param \Illuminate\Console\Command $command - * @return \Illuminate\Database\Seeder + * @return $this */ public function setCommand(Command $command) { From 6443cccc095aa9584e0250e1abf8e110a37944ca Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 1 Aug 2014 16:04:05 +0200 Subject: [PATCH 330/577] Replace more static return types --- Eloquent/Collection.php | 14 +++++++------- Eloquent/Model.php | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 8c41b4dbb..4301c2cda 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -73,7 +73,7 @@ public function contains($key) * Fetch a nested element of the collection. * * @param string $key - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function fetch($key) { @@ -122,7 +122,7 @@ public function modelKeys() * Merge the collection with the given items. * * @param \ArrayAccess|array $items - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function merge($items) { @@ -140,7 +140,7 @@ public function merge($items) * Diff the collection with the given items. * * @param \ArrayAccess|array $items - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function diff($items) { @@ -163,7 +163,7 @@ public function diff($items) * Intersect the collection with the given items. * * @param \ArrayAccess|array $items - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function intersect($items) { @@ -185,7 +185,7 @@ public function intersect($items) /** * Return only unique items from the collection. * - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function unique() { @@ -198,7 +198,7 @@ public function unique() * Returns only the models from the collection with the specified keys. * * @param mixed $keys - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function only($keys) { @@ -211,7 +211,7 @@ public function only($keys) * Returns all models in the collection except the models with specified keys. * * @param mixed $keys - * @return \Illuminate\Database\Eloquent\Collection + * @return static */ public function except($keys) { diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7f9fc4069..7c7898ab7 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -436,7 +436,7 @@ protected function fillableFromArray(array $attributes) * * @param array $attributes * @param bool $exists - * @return \Illuminate\Database\Eloquent\Model|static + * @return static */ public function newInstance($attributes = array(), $exists = false) { @@ -454,7 +454,7 @@ public function newInstance($attributes = array(), $exists = false) * Create a new model instance that is existing. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model|static + * @return static */ public function newFromBuilder($attributes = array()) { @@ -517,7 +517,7 @@ public static function hydrateRaw($query, $bindings = array(), $connection = nul * Save a new model and return the instance. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model|static + * @return static */ public static function create(array $attributes) { @@ -532,7 +532,7 @@ public static function create(array $attributes) * Get the first record matching the attributes or create it. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model + * @return static */ public static function firstOrCreate(array $attributes) { @@ -548,7 +548,7 @@ public static function firstOrCreate(array $attributes) * Get the first record matching the attributes or instantiate it. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model + * @return static */ public static function firstOrNew(array $attributes) { @@ -565,7 +565,7 @@ public static function firstOrNew(array $attributes) * * @param array $attributes * @param array $values - * @return \Illuminate\Database\Eloquent\Model + * @return static */ public static function updateOrCreate(array $attributes, array $values = array()) { @@ -580,7 +580,7 @@ public static function updateOrCreate(array $attributes, array $values = array() * Get the first model for the given attributes. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model|null + * @return static|null */ protected static function firstByAttributes($attributes) { @@ -633,7 +633,7 @@ public static function all($columns = array('*')) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|Collection|static + * @return \Illuminate\Support\Collection|static */ public static function find($id, $columns = array('*')) { @@ -649,7 +649,7 @@ public static function find($id, $columns = array('*')) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|Collection|static + * @return \Illuminate\Support\Collection|static */ public static function findOrNew($id, $columns = array('*')) { @@ -663,7 +663,7 @@ public static function findOrNew($id, $columns = array('*')) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|Collection|static + * @return \Illuminate\Support\Collection|static * * @throws ModelNotFoundException */ From 7af50462946771e44aa0f50a02ce5288a5122a89 Mon Sep 17 00:00:00 2001 From: tgolsen Date: Fri, 1 Aug 2014 17:36:57 -0400 Subject: [PATCH 331/577] minor comment addition in MySqlConnector.php --- Connectors/MySqlConnector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index f9518cbf1..c10563d54 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -48,7 +48,8 @@ public function connect(array $config) } /** - * Create a DSN string from a configuration. + * Create a DSN string from a configuration. Chooses socket or host/port based on + * the 'unix_socket' config value * * @param array $config * @return string From 4c238c3499dfc671a2a3b443457766da77f2839a Mon Sep 17 00:00:00 2001 From: Valera Trubachev Date: Fri, 1 Aug 2014 16:39:35 -0500 Subject: [PATCH 332/577] Simplify code per JosephSilber's suggestion. --- Eloquent/Model.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 727a8d181..0f6e8b7b3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2682,32 +2682,23 @@ public function syncOriginalAttribute($attribute) /** * Determine if the model or given attribute(s) have been modified. * - * @param string|array|null $attribute + * @param string|array|null $attributes * @return bool */ - public function isDirty($attribute = null) + public function isDirty($attributes = null) { $dirty = $this->getDirty(); - if (func_num_args() > 1) $attribute = func_get_args(); + if (is_null($attributes)) return count($dirty) > 0; - if (is_null($attribute)) + if ( ! is_array($attributes)) $attributes = func_get_args(); + + foreach ($attributes as $attr) { - return count($dirty) > 0; + if (array_key_exists($attr, $dirty)) return true; } - elseif (is_array($attribute)) - { - foreach ($attribute as $attr) - { - if (array_key_exists($attr, $dirty)) return true; - } - return false; - } - else - { - return array_key_exists($attribute, $dirty); - } + return false; } /** From d3009148546294ef4861abd4f20ca6cbee1c6b55 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 3 Aug 2014 16:08:11 +0100 Subject: [PATCH 333/577] Corrected eloquent priority docblocks --- Eloquent/Model.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index f61392e16..0265e1ec7 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1126,7 +1126,7 @@ protected function performDeleteOnModel() * Register a saving model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function saving($callback, $priority = 0) @@ -1138,7 +1138,7 @@ public static function saving($callback, $priority = 0) * Register a saved model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function saved($callback, $priority = 0) @@ -1150,7 +1150,7 @@ public static function saved($callback, $priority = 0) * Register an updating model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function updating($callback, $priority = 0) @@ -1162,7 +1162,7 @@ public static function updating($callback, $priority = 0) * Register an updated model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function updated($callback, $priority = 0) @@ -1174,7 +1174,7 @@ public static function updated($callback, $priority = 0) * Register a creating model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function creating($callback, $priority = 0) @@ -1186,7 +1186,7 @@ public static function creating($callback, $priority = 0) * Register a created model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function created($callback, $priority = 0) @@ -1198,7 +1198,7 @@ public static function created($callback, $priority = 0) * Register a deleting model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function deleting($callback, $priority = 0) @@ -1210,7 +1210,7 @@ public static function deleting($callback, $priority = 0) * Register a deleted model event with the dispatcher. * * @param \Closure|string $callback - * @param int $priority + * @param int $priority * @return void */ public static function deleted($callback, $priority = 0) From 79a1220ed52e406e7a3ce991c738d19f2982ed89 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 3 Aug 2014 11:10:25 -0500 Subject: [PATCH 334/577] cleaning up some code. --- Connectors/MySqlConnector.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Connectors/MySqlConnector.php b/Connectors/MySqlConnector.php index c10563d54..46ad0a799 100755 --- a/Connectors/MySqlConnector.php +++ b/Connectors/MySqlConnector.php @@ -56,7 +56,18 @@ public function connect(array $config) */ protected function getDsn(array $config) { - return isset($config['unix_socket']) && !empty($config['unix_socket']) ? $this->getSocketDsn($config) : $this->getHostDsn($config); + return $this->configHasSocket($config) ? $this->getSocketDsn($config) : $this->getHostDsn($config); + } + + /** + * Determine if the given configuration array has a UNIX socket value. + * + * @param array $config + * @return bool + */ + protected function configHasSocket(array $config) + { + return isset($config['unix_socket']) && ! empty($config['unix_socket']); } /** From 5b86733246e46be6a86593273fab62188412f335 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 3 Aug 2014 19:58:45 -0500 Subject: [PATCH 335/577] Automatically retry queries on database connections that have 'gone away'. --- Connection.php | 135 ++++++++++++++++++++++++++++++++++++++++---- DatabaseManager.php | 21 +++++-- QueryException.php | 2 + 3 files changed, 143 insertions(+), 15 deletions(-) diff --git a/Connection.php b/Connection.php index b15374aff..afe4ddc19 100755 --- a/Connection.php +++ b/Connection.php @@ -22,6 +22,13 @@ class Connection implements ConnectionInterface { */ protected $readPdo; + /** + * The reconnector instance for the connection. + * + * @var callable + */ + protected $reconnector; + /** * The query grammar implementation. * @@ -537,8 +544,46 @@ public function pretend(Closure $callback) */ protected function run($query, $bindings, Closure $callback) { + $this->reconnectIfMissingConnection(); + $start = microtime(true); + // Here we will run this query. If an exception occurs we'll determine if it was + // caused by a connection that has been lost. If that is the cause, we'll try + // to re-establish connection and re-run the query with a fresh connection. + try + { + $result = $this->runQueryCallback($query, $bindings, $callback); + } + catch (QueryException $e) + { + $result = $this->tryAgainIfCausedByLostConnection( + $e, $query, $bindings, $callback + ); + } + + // Once we have run the query we will calculate the time that it took to run and + // then log the query, bindings, and execution time so we will report them on + // the event that the developer needs them. We'll log time in milliseconds. + $time = $this->getElapsedTime($start); + + $this->logQuery($query, $bindings, $time); + + return $result; + } + + /** + * Run a SQL statement. + * + * @param string $query + * @param array $bindings + * @param \Closure $callback + * @return mixed + * + * @throws QueryException + */ + protected function runQueryCallback($query, $bindings, Closure $callback) + { // To execute the statement, we'll simply call the callback, which will actually // run the SQL against the PDO connection. Then we can calculate the time it // took to execute and log the query SQL, bindings and time in our memory. @@ -552,17 +597,72 @@ protected function run($query, $bindings, Closure $callback) // lot more helpful to the developer instead of just the database's errors. catch (\Exception $e) { - throw new QueryException($query, $this->prepareBindings($bindings), $e); + throw new QueryException( + $query, $this->prepareBindings($bindings), $e + ); } - // Once we have run the query we will calculate the time that it took to run and - // then log the query, bindings, and execution time so we will report them on - // the event that the developer needs them. We'll log time in milliseconds. - $time = $this->getElapsedTime($start); + return $result; + } - $this->logQuery($query, $bindings, $time); + /** + * Handle a query exception that occurred during query execution. + * + * @param \Illuminate\Database\QueryException $e + * @param string $query + * @param array $bindings + * @param \Closure $callback + * @return mixed + */ + protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, $callback) + { + if ($this->causedByLostConnection($e)) + { + $this->reconnect(); - return $result; + return $this->runQueryCallback($query, $bindings, $callback); + } + + throw $e; + } + + /** + * Determine if the given exception was caused by a lost connection. + * + * @param \Illuminate\Database\QueryException + * @return bool + */ + protected function causedByLostConnection(QueryException $e) + { + return str_contains($e->getPrevious()->getMessage(), 'server has gone away'); + } + + /** + * Reconnect to the database. + * + * @return void + */ + public function reconnect() + { + if (is_callable($this->reconnector)) + { + return call_user_func($this->reconnector, $this); + } + + throw new \LogicException("Lost connection and no reconnector available."); + } + + /** + * Reconnect to the database if a PDO connection is missing. + * + * @return void + */ + protected function reconnectIfMissingConnection() + { + if (is_null($this->getPdo()) || is_null($this->getReadPdo())) + { + $this->reconnect(); + } } /** @@ -687,10 +787,10 @@ public function getReadPdo() /** * Set the PDO connection. * - * @param \PDO $pdo + * @param \PDO|null $pdo * @return $this */ - public function setPdo(PDO $pdo) + public function setPdo($pdo) { $this->pdo = $pdo; @@ -700,16 +800,29 @@ public function setPdo(PDO $pdo) /** * Set the PDO connection used for reading. * - * @param \PDO $pdo + * @param \PDO|null $pdo * @return $this */ - public function setReadPdo(PDO $pdo) + public function setReadPdo($pdo) { $this->readPdo = $pdo; return $this; } + /** + * Set the reconnect instance on the connection. + * + * @param callable $reconnector + * @return $this + */ + public function setReconnector(callable $reconnector) + { + $this->reconnector = $reconnector; + + return $this; + } + /** * Get the database connection name. * diff --git a/DatabaseManager.php b/DatabaseManager.php index d426f24cd..e8bfd7897 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -76,11 +76,13 @@ public function connection($name = null) */ public function reconnect($name = null) { - $name = $name ?: $this->getDefaultConnection(); + $this->disconnect($name = $name ?: $this->getDefaultConnection()); - $this->disconnect($name); + $fresh = $this->makeConnection($name); - return $this->connection($name); + return $this->connections[$name] + ->setPdo($fresh->getPdo()) + ->setReadPdo($fresh->getReadPdo()); } /** @@ -93,7 +95,10 @@ public function disconnect($name = null) { $name = $name ?: $this->getDefaultConnection(); - unset($this->connections[$name]); + if (isset($this->connections[$name])) + { + $this->connections[$name]->setPdo(null)->setReadPdo(null); + } } /** @@ -160,6 +165,14 @@ protected function prepare(Connection $connection) return $app['paginator']; }); + // Here we'll set a reconnector callback. This reconnector can be any callable + // so we will set a Closure to reconnect from this manager with the name of + // the connection, which will allow us to reconnect from the connections. + $connection->setReconnector(function($connection) + { + $this->reconnect($connection->getName()); + }); + return $connection; } diff --git a/QueryException.php b/QueryException.php index c73dbf603..e3f9cf2fe 100644 --- a/QueryException.php +++ b/QueryException.php @@ -28,6 +28,8 @@ class QueryException extends PDOException { */ public function __construct($sql, array $bindings, $previous) { + parent::__construct('', 0, $previous); + $this->sql = $sql; $this->bindings = $bindings; $this->previous = $previous; From 845bc0a724a8f868522408bd4ac5394470603af2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 3 Aug 2014 20:09:30 -0500 Subject: [PATCH 336/577] Cleaning up some code. --- Connection.php | 10 ++++++++++ DatabaseManager.php | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Connection.php b/Connection.php index afe4ddc19..62aea70f3 100755 --- a/Connection.php +++ b/Connection.php @@ -637,6 +637,16 @@ protected function causedByLostConnection(QueryException $e) return str_contains($e->getPrevious()->getMessage(), 'server has gone away'); } + /** + * Disconnect from the underlying PDO connection. + * + * @return void + */ + public function disconnect() + { + $this->setPdo(null)->setReadPdo(null); + } + /** * Reconnect to the database. * diff --git a/DatabaseManager.php b/DatabaseManager.php index e8bfd7897..8fb51e284 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -68,6 +68,20 @@ public function connection($name = null) return $this->connections[$name]; } + /** + * Disconnect from the given database. + * + * @param string $name + * @return void + */ + public function disconnect($name = null) + { + if (isset($this->connections[$name = $name ?: $this->getDefaultConnection()])) + { + $this->connections[$name]->disconnect(); + } + } + /** * Reconnect to the given database. * @@ -78,27 +92,29 @@ public function reconnect($name = null) { $this->disconnect($name = $name ?: $this->getDefaultConnection()); - $fresh = $this->makeConnection($name); - - return $this->connections[$name] - ->setPdo($fresh->getPdo()) - ->setReadPdo($fresh->getReadPdo()); + if ( ! isset($this->connections[$name])) + { + return $this->connection($name); + } + else + { + return $this->refreshPdoConnections($name); + } } /** - * Disconnect from the given database. + * Refresh the PDO connections on a given connection. * * @param string $name - * @return void + * @return \Illuminate\Database\Connection */ - public function disconnect($name = null) + protected function refreshPdoConnections($name) { - $name = $name ?: $this->getDefaultConnection(); + $fresh = $this->makeConnection($name); - if (isset($this->connections[$name])) - { - $this->connections[$name]->setPdo(null)->setReadPdo(null); - } + return $this->connections[$name] + ->setPdo($fresh->getPdo()) + ->setReadPdo($fresh->getReadPdo()); } /** From 1cab8c5dba11f07f64fa30b99b15a959aec99d58 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Mon, 4 Aug 2014 11:58:18 -0300 Subject: [PATCH 337/577] [4.2] Database Docblock Fixes --- Connection.php | 8 ++++++-- Eloquent/Builder.php | 4 ++-- Eloquent/Model.php | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Connection.php b/Connection.php index 62aea70f3..4f9a97790 100755 --- a/Connection.php +++ b/Connection.php @@ -540,7 +540,7 @@ public function pretend(Closure $callback) * @param \Closure $callback * @return mixed * - * @throws QueryException + * @throws \Illuminate\Database\QueryException */ protected function run($query, $bindings, Closure $callback) { @@ -580,7 +580,7 @@ protected function run($query, $bindings, Closure $callback) * @param \Closure $callback * @return mixed * - * @throws QueryException + * @throws \Illuminate\Database\QueryException */ protected function runQueryCallback($query, $bindings, Closure $callback) { @@ -613,6 +613,8 @@ protected function runQueryCallback($query, $bindings, Closure $callback) * @param array $bindings * @param \Closure $callback * @return mixed + * + * @throws \Illuminate\Database\QueryException */ protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, $callback) { @@ -651,6 +653,8 @@ public function disconnect() * Reconnect to the database. * * @return void + * + * @throws \LogicException */ public function reconnect() { diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 74782959f..b0b2f41aa 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -105,7 +105,7 @@ public function findMany($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static * - * @throws ModelNotFoundException + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function findOrFail($id, $columns = array('*')) { @@ -131,7 +131,7 @@ public function first($columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static * - * @throws ModelNotFoundException + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function firstOrFail($columns = array('*')) { diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7c7898ab7..f75db1b4f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -389,7 +389,7 @@ public static function observe($class) * @param array $attributes * @return $this * - * @throws MassAssignmentException + * @throws \Illuminate\Database\Eloquent\MassAssignmentException */ public function fill(array $attributes) { @@ -665,7 +665,7 @@ public static function findOrNew($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Support\Collection|static * - * @throws ModelNotFoundException + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public static function findOrFail($id, $columns = array('*')) { From fbbe73265a0aac703512a6ee82c6d34017ee3e29 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Mon, 4 Aug 2014 15:56:54 -0300 Subject: [PATCH 338/577] Added typehint to tryAgainIfCausedByLostConnection --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index 4f9a97790..bf32d4e73 100755 --- a/Connection.php +++ b/Connection.php @@ -616,7 +616,7 @@ protected function runQueryCallback($query, $bindings, Closure $callback) * * @throws \Illuminate\Database\QueryException */ - protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, $callback) + protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback) { if ($this->causedByLostConnection($e)) { From bf0aa64e64d4cf1c6f9b597376167d76bfe4cf8d Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Tue, 5 Aug 2014 21:44:53 +1000 Subject: [PATCH 339/577] Implement RouteableInterface to ease routing with Eloquent models --- Eloquent/Model.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9d55a1ae3..b6b07344c 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Contracts\JsonableInterface; use Illuminate\Support\Contracts\ArrayableInterface; +use Illuminate\Support\Contracts\RouteableInterface; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -22,7 +23,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, JsonSerializable { +abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, RouteableInterface, JsonSerializable { /** * The connection name for the model. @@ -1874,6 +1875,26 @@ public function getQualifiedKeyName() return $this->getTable().'.'.$this->getKeyName(); } + /** + * Get the value of the model's route key. + * + * @return mixed + */ + public function getRouteKey() + { + $this->getAttribute($this->getRouteKeyName()); + } + + /** + * Get the route key for the model. + * + * @return string + */ + public function getRouteKeyName() + { + return $this->getKeyName(); + } + /** * Determine if the model uses timestamps. * From ad52f165366803a7cfe9ca308a17cc257e90c661 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Tue, 5 Aug 2014 22:08:13 +1000 Subject: [PATCH 340/577] Return the model's route key --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b6b07344c..73fd48ab5 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1882,7 +1882,7 @@ public function getQualifiedKeyName() */ public function getRouteKey() { - $this->getAttribute($this->getRouteKeyName()); + return $this->getAttribute($this->getRouteKeyName()); } /** From 0c4714accc27fa291789484e5a068a52ce7975d9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 5 Aug 2014 14:35:51 -0500 Subject: [PATCH 341/577] Added purge method. --- DatabaseManager.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/DatabaseManager.php b/DatabaseManager.php index 8fb51e284..b188f4417 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -68,6 +68,19 @@ public function connection($name = null) return $this->connections[$name]; } + /** + * Disconnect from the given database and remove from local cache. + * + * @param string $name + * @return void + */ + public function purge($name = null) + { + $this->disconnect($name); + + unset($this->connections[$name]); + } + /** * Disconnect from the given database. * From d9693751bac22feb5804b0c0a85289a295ba1073 Mon Sep 17 00:00:00 2001 From: Jarek Tkaczyk Date: Wed, 6 Aug 2014 00:23:51 +0200 Subject: [PATCH 342/577] 4.2 Fix select on belongsToMany eager load --- Eloquent/Relations/BelongsToMany.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 776b38aba..eba6ea802 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -139,6 +139,8 @@ public function get($columns = array('*')) // First we'll add the proper select columns onto the query so it is run with // the proper columns. Then, we will get the results and hydrate out pivot // models with the result of those columns as a separate model relation. + $columns = $this->query->getQuery()->columns ? array() : $columns; + $select = $this->getSelectColumns($columns); $models = $this->query->addSelect($select)->getModels(); From e30e952955c52a298d188706105ce1b7d843f383 Mon Sep 17 00:00:00 2001 From: crynobone Date: Wed, 6 Aug 2014 13:15:33 +0800 Subject: [PATCH 343/577] Add ability to automatically resolve DB::connection('mysql::write') to use writable database connection as well as DB::connection('mysql::read') instead of adding duplicate connection config. Signed-off-by: crynobone --- DatabaseManager.php | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index b188f4417..44d11eac1 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -1,6 +1,7 @@ getDefaultConnection(); + $name = $driver = $name ?: $this->getDefaultConnection(); + $type = null; + + if (Str::endsWith($name, ['::write', '::read'])) + { + list($driver, $type) = explode('::', $name, 2); + } // If we haven't created this connection, we'll create it based on the config // provided in the application. Once we've created the connections we will // set the "fetch mode" for PDO which determines the query return types. if ( ! isset($this->connections[$name])) { - $connection = $this->makeConnection($name); + $connection = $this->makeConnection($driver); + + $connection = $this->prepareReadWriteMode($connection, $type); $this->connections[$name] = $this->prepare($connection); } @@ -205,6 +214,27 @@ protected function prepare(Connection $connection) return $connection; } + /** + * Prepare the read write mode for database connection instance. + * + * @param \Illuminate\Database\Connection $connection + * @param string $type + * @return \Illuminate\Database\Connection + */ + protected function prepareReadWriteMode($connection, $type = null) + { + if ($type == 'read') + { + $connection->setPdo($connection->getReadPdo()); + } + elseif ($type == 'write') + { + $connection->setReadPdo($connection->getPdo()); + } + + return $connection; + } + /** * Get the configuration for a connection. * From 4d5103f99f292ede8dc6909cc4e9e04b13d301f4 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 7 Aug 2014 13:28:31 +0200 Subject: [PATCH 344/577] Replace 'dynamic' keyword with 'mixed' 'dynamic' is not a valid keyword, see http://phpdoc.org/docs/latest/guides/types.html#keywords --- Eloquent/Builder.php | 2 +- Query/Builder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 74782959f..d7521bd9d 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -711,7 +711,7 @@ protected function getHasRelationQuery($relation) /** * Set the relationships that should be eager loaded. * - * @param dynamic $relations + * @param mixed $relations * @return $this */ public function with($relations) diff --git a/Query/Builder.php b/Query/Builder.php index 5dc368f89..e13f52b3d 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1262,7 +1262,7 @@ public function rememberForever($key = null) /** * Indicate that the results, if cached, should use the given cache tags. * - * @param array|dynamic $cacheTags + * @param array|mixed $cacheTags * @return $this */ public function cacheTags($cacheTags) From 6b03f8f2eb169a80ea4ba73e5e3679fabf51eb23 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 7 Aug 2014 14:15:10 +0200 Subject: [PATCH 345/577] Use FQN in phpdocs --- Connection.php | 4 ++-- Connectors/Connector.php | 2 +- Connectors/PostgresConnector.php | 2 +- Connectors/SqlServerConnector.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Connection.php b/Connection.php index 62aea70f3..829070c20 100755 --- a/Connection.php +++ b/Connection.php @@ -775,7 +775,7 @@ public function getDoctrineConnection() /** * Get the current PDO connection. * - * @return PDO + * @return \PDO */ public function getPdo() { @@ -785,7 +785,7 @@ public function getPdo() /** * Get the current PDO connection used for reading. * - * @return PDO + * @return \PDO */ public function getReadPdo() { diff --git a/Connectors/Connector.php b/Connectors/Connector.php index 90648b6f3..0c16093b4 100755 --- a/Connectors/Connector.php +++ b/Connectors/Connector.php @@ -36,7 +36,7 @@ public function getOptions(array $config) * @param string $dsn * @param array $config * @param array $options - * @return PDO + * @return \PDO */ public function createConnection($dsn, array $config, array $options) { diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index ed2050026..1b2ca080d 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -20,7 +20,7 @@ class PostgresConnector extends Connector implements ConnectorInterface { * Establish a database connection. * * @param array $config - * @return PDO + * @return \PDO */ public function connect(array $config) { diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index deb7d34d4..1d81fe572 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -20,7 +20,7 @@ class SqlServerConnector extends Connector implements ConnectorInterface { * Establish a database connection. * * @param array $config - * @return PDO + * @return \PDO */ public function connect(array $config) { From 603278ec4c7146180dbb25024980a01687baf786 Mon Sep 17 00:00:00 2001 From: Jens Segers Date: Fri, 8 Aug 2014 16:50:24 +0200 Subject: [PATCH 346/577] Fix typo in HasOneOrMany --- Eloquent/Relations/HasOneOrMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 87bc4afe5..83bc7eee2 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -269,7 +269,7 @@ public function getPlainForeignKey() } /** - * Get the key value of the paren's local key. + * Get the key value of the parent's local key. * * @return mixed */ From 60cc0c04a18a8fc84ff0f5bac2843facb48de281 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 4 Aug 2014 11:12:54 +0100 Subject: [PATCH 347/577] Corrected a docblock --- Eloquent/Relations/MorphTo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index f2f8f9e51..acd7c027c 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -67,7 +67,7 @@ public function addEagerConstraints(array $models) /** * Build a dictionary with the models. * - * @param \Illuminate\Database\Eloquent\Models $models + * @param \Illuminate\Database\Eloquent\Collection $models * @return void */ protected function buildDictionary(Collection $models) From 2f19f81c43d85d32727562bb1716db973d6fa358 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 13 Aug 2014 14:45:38 -0400 Subject: [PATCH 348/577] Update docblocks for Eloquent Model --- Eloquent/Model.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7c7898ab7..008cfdf15 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -352,7 +352,7 @@ public static function getGlobalScope($scope) /** * Get the global scopes for this class instance. * - * @return array + * @return \Illuminate\Database\Eloquent\ScopeInterface[] */ public function getGlobalScopes() { @@ -590,7 +590,7 @@ protected static function firstByAttributes($attributes) /** * Begin querying the model. * - * @return \Illuminate\Database\Eloquent\Builder|static + * @return \Illuminate\Database\Eloquent\Builder */ public static function query() { @@ -601,7 +601,7 @@ public static function query() * Begin querying the model on a given connection. * * @param string $connection - * @return \Illuminate\Database\Eloquent\Builder|static + * @return \Illuminate\Database\Eloquent\Builder */ public static function on($connection = null) { @@ -1691,7 +1691,7 @@ public function freshTimestampString() /** * Get a new query builder for the model's table. * - * @return \Illuminate\Database\Eloquent\Builder|static + * @return \Illuminate\Database\Eloquent\Builder */ public function newQuery() { @@ -1750,7 +1750,7 @@ public function applyGlobalScopes($builder) * Remove all of the global scopes from an Eloquent builder. * * @param \Illuminate\Database\Eloquent\Builder $builder - * @return void + * @return \Illuminate\Database\Eloquent\Builder */ public function removeGlobalScopes($builder) { From 5a14cf9b83eba3aad332d6eba38ae1aecb06ccf7 Mon Sep 17 00:00:00 2001 From: Kevin D Date: Thu, 14 Aug 2014 15:07:12 -0700 Subject: [PATCH 349/577] Global scope joins broken when using Find Make Builder::find and Builder::findMany use the fully qualified names so global scopes can still work. --- Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index d7521bd9d..459d41e53 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -77,7 +77,7 @@ public function find($id, $columns = array('*')) return $this->findMany($id, $columns); } - $this->query->where($this->model->getKeyName(), '=', $id); + $this->query->where($this->model->getQualifiedKeyName(), '=', $id); return $this->first($columns); } @@ -93,7 +93,7 @@ public function findMany($id, $columns = array('*')) { if (empty($id)) return $this->model->newCollection(); - $this->query->whereIn($this->model->getKeyName(), $id); + $this->query->whereIn($this->model->getQualifiedKeyName(), $id); return $this->get($columns); } From 4920a55b31fd68a073af2f581256d9cb2f21e15f Mon Sep 17 00:00:00 2001 From: benti Date: Fri, 15 Aug 2014 10:00:33 +0200 Subject: [PATCH 350/577] Fixed wrong @return type. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index d7521bd9d..cc340f7e0 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -405,7 +405,7 @@ public function onDelete(Closure $callback) * Get the hydrated models without eager loading. * * @param array $columns - * @return array|static[] + * @return \Illuminate\Database\Eloquent\Model[] */ public function getModels($columns = array('*')) { From fadf6cb3955b8642b59bc7d6f11af20e70643b3a Mon Sep 17 00:00:00 2001 From: johnparn Date: Mon, 18 Aug 2014 06:13:06 +0200 Subject: [PATCH 351/577] Support for sslmode in PostgresConnector.php This change makes it possible to specify sslmode when connecting to PostgreSQL, ie use SSL encrypted connection between the web app and the database. Of course it requires some configuration of your PostgreSQL instance to make it work. I've tested this with the database config value 'require' to make the SSL connection mandatory and setting hostssl in pg_hba.conf for all connections. Possible sslmode values depend on the version of the pgsql library: 'disable', 'allow', 'prefer', 'require', 'verify-ca', 'verify-full'. The default value is 'prefer'. The value 'require' is backwards compatible. For further info check the PostgreSQL docs: http://www.postgresql.org/docs/9.3/static/libpq-ssl.html --- Connectors/PostgresConnector.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 1b2ca080d..9b40ff5a8 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -74,6 +74,15 @@ protected function getDsn(array $config) { $dsn .= ";port={$port}"; } + + // If sslmode was specified, add it to this Postgres DSN connections + // format. This setting will turn on/off the encryption of the connection + // between the app and database. For example, set it to 'require' to ensure + // encrypted connection. + if (isset($config['sslmode'])) + { + $dsn .= ";sslmode={$sslmode}"; + } return $dsn; } From 61ff6392d449ac83552cafae540922430fdab25d Mon Sep 17 00:00:00 2001 From: Abdelmadjid Hammou Date: Mon, 18 Aug 2014 13:37:10 -0400 Subject: [PATCH 352/577] Only include migrations that need to run to preserve RAM. --- Migrations/Migrator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 10806f5ca..526eead71 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -68,7 +68,7 @@ public function run($path, $pretend = false) { $this->notes = array(); - $this->requireFiles($path, $files = $this->getMigrationFiles($path)); + $files = $this->getMigrationFiles($path); // Once we grab all of the migration files for the path, we will compare them // against the migrations that have already been run for this package then @@ -76,6 +76,7 @@ public function run($path, $pretend = false) $ran = $this->repository->getRan(); $migrations = array_diff($files, $ran); + $this->requireFiles($path, $migrations); $this->runMigrationList($migrations, $pretend); } From 2c9305b58c9f58c489a972ae3203635bb8fe166a Mon Sep 17 00:00:00 2001 From: Abdelmadjid Hammou Date: Mon, 18 Aug 2014 14:07:15 -0400 Subject: [PATCH 353/577] Fixed indentation --- Migrations/Migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 526eead71..38fbd7c90 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -68,7 +68,7 @@ public function run($path, $pretend = false) { $this->notes = array(); - $files = $this->getMigrationFiles($path); + $files = $this->getMigrationFiles($path); // Once we grab all of the migration files for the path, we will compare them // against the migrations that have already been run for this package then From 0c6f6f202b6b5dda5b62329c428879d15b2af81b Mon Sep 17 00:00:00 2001 From: Jildert Miedema Date: Wed, 20 Aug 2014 16:41:57 +0200 Subject: [PATCH 354/577] Set index name of morph relation The index name auto generated index name can become long and with this method it can be overridden --- Schema/Blueprint.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 22f82ca31..cb3de29ad 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -663,13 +663,13 @@ public function binary($column) * @param string $name * @return void */ - public function morphs($name) + public function morphs($name, $indexName = null) { $this->unsignedInteger("{$name}_id"); $this->string("{$name}_type"); - $this->index(array("{$name}_id", "{$name}_type")); + $this->index(array("{$name}_id", "{$name}_type"), $indexName); } /** From f0880dc62570fe14860f774a35fc3ed230350d05 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 21 Aug 2014 12:26:56 +0200 Subject: [PATCH 355/577] Extract getClassName method Make it easier to customize the migration naming schema. --- Migrations/MigrationCreator.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index e62a53130..de1fc5be5 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -90,7 +90,7 @@ protected function getStub($table, $create) */ protected function populateStub($name, $stub, $table) { - $stub = str_replace('{{class}}', studly_case($name), $stub); + $stub = str_replace('{{class}}', $this->getClassName($name), $stub); // Here we will replace the table place-holders with the table specified by // the developer, which is useful for quickly creating a tables creation @@ -103,6 +103,17 @@ protected function populateStub($name, $stub, $table) return $stub; } + /** + * Get the class name of a migration name. + * + * @param string $name + * @return string + */ + protected function getClassName($name) + { + return studly_case($name); + } + /** * Fire the registered post create hooks. * From a9256f271a1f17d790e5f353ed3dd3df6c803c48 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Thu, 21 Aug 2014 13:02:47 +0200 Subject: [PATCH 356/577] Extract registerCreator method Make it easier to register a custom creator. --- MigrationServiceProvider.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 797d7fb46..0b2faafcb 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -171,10 +171,7 @@ protected function registerInstallCommand() */ protected function registerMakeCommand() { - $this->app->bindShared('migration.creator', function($app) - { - return new MigrationCreator($app['files']); - }); + $this->registerCreator(); $this->app->bindShared('command.migrate.make', function($app) { @@ -189,6 +186,19 @@ protected function registerMakeCommand() }); } + /** + * Register the migration creator. + * + * @return void + */ + protected function registerCreator() + { + $this->app->bindShared('migration.creator', function($app) + { + return new MigrationCreator($app['files']); + }); + } + /** * Get the services provided by the provider. * From 74d301bf9047e4f5f8ebd6460d5e7725bc146e15 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Aug 2014 13:43:48 -0500 Subject: [PATCH 357/577] Implement contracts for many major components of the framework. --- Capsule/Manager.php | 6 +++--- Connection.php | 8 ++++---- Eloquent/Model.php | 12 ++++++------ composer.json | 3 +-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 374d9c7a2..b61c4df5d 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -2,10 +2,10 @@ use PDO; use Illuminate\Support\Fluent; -use Illuminate\Events\Dispatcher; use Illuminate\Cache\CacheManager; use Illuminate\Container\Container; use Illuminate\Database\DatabaseManager; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Connectors\ConnectionFactory; @@ -205,7 +205,7 @@ public function getDatabaseManager() /** * Get the current event dispatcher instance. * - * @return \Illuminate\Events\Dispatcher + * @return \Illuminate\Contracts\Events\Dispatcher */ public function getEventDispatcher() { @@ -218,7 +218,7 @@ public function getEventDispatcher() /** * Set the event dispatcher instance to be used by connections. * - * @param \Illuminate\Events\Dispatcher $dispatcher + * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher * @return void */ public function setEventDispatcher(Dispatcher $dispatcher) diff --git a/Connection.php b/Connection.php index 829070c20..3266508e8 100755 --- a/Connection.php +++ b/Connection.php @@ -53,7 +53,7 @@ class Connection implements ConnectionInterface { /** * The event dispatcher instance. * - * @var \Illuminate\Events\Dispatcher + * @var \Illuminate\Contracts\Events\Dispatcher */ protected $events; @@ -930,7 +930,7 @@ public function setPostProcessor(Processor $processor) /** * Get the event dispatcher used by the connection. * - * @return \Illuminate\Events\Dispatcher + * @return \Illuminate\Contracts\Events\Dispatcher */ public function getEventDispatcher() { @@ -940,10 +940,10 @@ public function getEventDispatcher() /** * Set the event dispatcher instance on the connection. * - * @param \Illuminate\Events\Dispatcher + * @param \Illuminate\Contracts\Events\Dispatcher * @return void */ - public function setEventDispatcher(\Illuminate\Events\Dispatcher $events) + public function setEventDispatcher(\Illuminate\Contracts\Events\Dispatcher $events) { $this->events = $events; } diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 262ea7a77..db668d075 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -5,13 +5,13 @@ use Carbon\Carbon; use LogicException; use JsonSerializable; -use Illuminate\Events\Dispatcher; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; -use Illuminate\Support\Contracts\JsonableInterface; -use Illuminate\Support\Contracts\ArrayableInterface; +use Illuminate\Contracts\Support\JsonableInterface; +use Illuminate\Contracts\Support\ArrayableInterface; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -181,7 +181,7 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa /** * The event dispatcher instance. * - * @var \Illuminate\Events\Dispatcher + * @var \Illuminate\Contracts\Events\Dispatcher */ protected static $dispatcher; @@ -2874,7 +2874,7 @@ public static function unsetConnectionResolver() /** * Get the event dispatcher instance. * - * @return \Illuminate\Events\Dispatcher + * @return \Illuminate\Contracts\Events\Dispatcher */ public static function getEventDispatcher() { @@ -2884,7 +2884,7 @@ public static function getEventDispatcher() /** * Set the event dispatcher instance. * - * @param \Illuminate\Events\Dispatcher $dispatcher + * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher * @return void */ public static function setEventDispatcher(Dispatcher $dispatcher) diff --git a/composer.json b/composer.json index 82e3989e5..2539357a5 100755 --- a/composer.json +++ b/composer.json @@ -11,12 +11,11 @@ "require": { "php": ">=5.4.0", "illuminate/container": "4.3.*", - "illuminate/events": "4.3.*", + "illuminate/contracts": "4.3.*", "illuminate/support": "4.3.*", "nesbot/carbon": "~1.0" }, "require-dev": { - "illuminate/cache": "4.3.*", "illuminate/console": "4.3.*", "illuminate/filesystem": "4.3.*", "illuminate/pagination": "4.3.*", From c4ee388b32067eab952c7613699f52091a736587 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Aug 2014 14:35:21 -0500 Subject: [PATCH 358/577] Group generators and publishers under single CLI namespace. --- Console/Migrations/MigrateMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/MigrateMakeCommand.php b/Console/Migrations/MigrateMakeCommand.php index 5fc6933eb..68c4be463 100644 --- a/Console/Migrations/MigrateMakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -11,7 +11,7 @@ class MigrateMakeCommand extends BaseCommand { * * @var string */ - protected $name = 'migrate:make'; + protected $name = 'make:migration'; /** * The console command description. From 2e890c854c0f2f37594d8880aaff3a6ef788afee Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Aug 2014 04:27:53 +0200 Subject: [PATCH 359/577] Fix migration path. --- Console/Migrations/BaseCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 7dfef5770..7c0d31187 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -43,7 +43,7 @@ protected function getMigrationPath() return $this->laravel['path.base'].$path; } - return $this->laravel['path'].'/database/migrations'; + return $this->laravel['path.database'].'/migrations'; } } From 7f47e13b913923b3f2d6ec0fa0cab8f7c263a19b Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 29 Aug 2014 11:02:08 +0200 Subject: [PATCH 360/577] Faster int cast --- Eloquent/Relations/BelongsToMany.php | 2 +- Schema/Grammars/Grammar.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 776b38aba..3cf77d533 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -586,7 +586,7 @@ public function sync($ids, $detaching = true) { $this->detach($detach); - $changes['detached'] = (array) array_map('intval', $detach); + $changes['detached'] = (array) array_map(function($v) { return (int) $v; }, $detach); } // Now we are finally ready to attach the new records. Note that we'll disable diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index 531d5793c..b45d09526 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -244,7 +244,7 @@ protected function getDefaultValue($value) { if ($value instanceof Expression) return $value; - if (is_bool($value)) return "'".intval($value)."'"; + if (is_bool($value)) return "'".(int) $value."'"; return "'".strval($value)."'"; } From 49c64b1057ed72ae6023175bb20ef56c531dff00 Mon Sep 17 00:00:00 2001 From: Mathieu Hamonic Date: Fri, 29 Aug 2014 14:06:48 +0200 Subject: [PATCH 361/577] Ensure to propagate touchOwner on relationships. --- Eloquent/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 008cfdf15..94156ab21 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1529,6 +1529,7 @@ public function touchOwners() foreach ($this->touches as $relation) { $this->$relation()->touch(); + $this->$relation->touchOwners(); } } From 29a694866d202c3f542aa8903ba67cce75e4619f Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 29 Aug 2014 10:24:16 +0200 Subject: [PATCH 362/577] Remove useless $app argument --- MigrationServiceProvider.php | 2 +- SeedServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 0b2faafcb..f7f0fccab 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -145,7 +145,7 @@ protected function registerResetCommand() */ protected function registerRefreshCommand() { - $this->app->bindShared('command.migrate.refresh', function($app) + $this->app->bindShared('command.migrate.refresh', function() { return new RefreshCommand; }); diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index be9291352..7b5e6d44c 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -21,7 +21,7 @@ public function register() { $this->registerSeedCommand(); - $this->app->bindShared('seeder', function($app) + $this->app->bindShared('seeder', function() { return new Seeder; }); From a41d2408699dae54ad942f782682c2bd012bc73b Mon Sep 17 00:00:00 2001 From: Andy Zhang Date: Wed, 3 Sep 2014 10:41:41 +1000 Subject: [PATCH 363/577] Fix morphToMany's pivot update and delete bug. --- Eloquent/Relations/MorphPivot.php | 23 +++++++++++++++++++++++ Eloquent/Relations/MorphToMany.php | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index adcf67de1..f9ffe63dd 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -13,6 +13,15 @@ class MorphPivot extends Pivot { */ protected $morphType; + /** + * The value of the polymorphic relation. + * + * Explicitly define this so it's not included in saved attributes. + * + * @var string + */ + protected $morphClass; + /** * Set the keys for a save update query. * @@ -53,4 +62,18 @@ public function setMorphType($morphType) return $this; } + /** + * Set the morph class for the pivot. + * + * @param string $morphClass + * @return \Illuminate\Database\Eloquent\Relations\MorphPivot + */ + public function setMorphClass($morphClass) + { + $this->morphClass = $morphClass; + + return $this; + } + + } diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 671fdc422..b376aa53f 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -128,9 +128,9 @@ public function newPivot(array $attributes = array(), $exists = false) { $pivot = new MorphPivot($this->parent, $attributes, $this->table, $exists); - $pivot->setPivotKeys($this->foreignKey, $this->otherKey); - - $pivot->setMorphType($this->morphType); + $pivot->setPivotKeys($this->foreignKey, $this->otherKey) + ->setMorphType($this->morphType) + ->setMorphClass($this->morphClass); return $pivot; } From 273a6f707c9329679b8dadd457985bc5000ae741 Mon Sep 17 00:00:00 2001 From: Kelly Banman Date: Thu, 4 Sep 2014 18:39:01 -0700 Subject: [PATCH 364/577] Fix calling BelongsToMany::detach() with a single id --- Eloquent/Relations/BelongsToMany.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 3cf77d533..0361b9506 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -829,10 +829,14 @@ public function detach($ids = array(), $touch = true) // We'll return the numbers of affected rows when we do the deletes. $ids = (array) $ids; - if (count($ids) > 0) + if (count($ids) > 1) { $query->whereIn($this->otherKey, $ids); } + elseif (count($ids) === 1) + { + $query->where($this->otherKey, reset($ids)); + } if ($touch) $this->touchIfTouching(); From 2da38583dacacca295cd596013876a6c22959339 Mon Sep 17 00:00:00 2001 From: nateemerson Date: Fri, 5 Sep 2014 10:00:30 -0700 Subject: [PATCH 365/577] Remove superfluous if condition in Model The method `Model::fromDateTime()` method has an if/else chain that terminates in a statement that will always evaluate to true given the control flow. The first if condition in the chain is `if ($value instanceof DateTime)`, while the final elseif condition is `elseif ( ! $value instanceof DateTime)`. Since the first condition must be true to arrive at the final check, the negation will always be true at that point, so it is a superfluous condition. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 008cfdf15..66320391a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2542,7 +2542,7 @@ public function fromDateTime($value) // If this value is some other type of string, we'll create the DateTime with // the format used by the database connection. Once we get the instance we // can return back the finally formatted DateTime instances to the devs. - elseif ( ! $value instanceof DateTime) + else { $value = Carbon::createFromFormat($format, $value); } From 9503aa0e850f7ec088d6f2be198f265512b788c6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Sep 2014 21:38:51 -0500 Subject: [PATCH 366/577] Just cast IDs to array. --- Eloquent/Relations/BelongsToMany.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 0361b9506..db2ffcb3f 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -829,13 +829,9 @@ public function detach($ids = array(), $touch = true) // We'll return the numbers of affected rows when we do the deletes. $ids = (array) $ids; - if (count($ids) > 1) - { - $query->whereIn($this->otherKey, $ids); - } - elseif (count($ids) === 1) + if (count($ids) > 0) { - $query->where($this->otherKey, reset($ids)); + $query->whereIn($this->otherKey, (array) $ids); } if ($touch) $this->touchIfTouching(); From 3486aea701d31548323280c226fafecb58be2118 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Sep 2014 22:09:11 -0500 Subject: [PATCH 367/577] Spacing. --- Eloquent/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index fc7bc4dd0..fe122c23a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1529,6 +1529,7 @@ public function touchOwners() foreach ($this->touches as $relation) { $this->$relation()->touch(); + $this->$relation->touchOwners(); } } From 86fa5b5a501ad92033bc3f69b3effc3b21c6c5ba Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 10:10:48 -0500 Subject: [PATCH 368/577] Spacing. --- Migrations/Migrator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Migrations/Migrator.php b/Migrations/Migrator.php index 38fbd7c90..fcb0e41bd 100755 --- a/Migrations/Migrator.php +++ b/Migrations/Migrator.php @@ -76,6 +76,7 @@ public function run($path, $pretend = false) $ran = $this->repository->getRan(); $migrations = array_diff($files, $ran); + $this->requireFiles($path, $migrations); $this->runMigrationList($migrations, $pretend); From 400a294d573ba15ef881442d3675b23b14422a89 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 10:11:59 -0500 Subject: [PATCH 369/577] Clean up comment. --- Connectors/PostgresConnector.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 9b40ff5a8..39b50e37b 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -74,11 +74,7 @@ protected function getDsn(array $config) { $dsn .= ";port={$port}"; } - - // If sslmode was specified, add it to this Postgres DSN connections - // format. This setting will turn on/off the encryption of the connection - // between the app and database. For example, set it to 'require' to ensure - // encrypted connection. + if (isset($config['sslmode'])) { $dsn .= ";sslmode={$sslmode}"; From 7002dd94c437710a73115411b61dffa231d40f48 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 12:01:01 -0500 Subject: [PATCH 370/577] Cleaning up some code. --- DatabaseManager.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 44d11eac1..b6ccdb502 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -1,7 +1,7 @@ getDefaultConnection(); - $type = null; - - if (Str::endsWith($name, ['::write', '::read'])) - { - list($driver, $type) = explode('::', $name, 2); - } + list($name, $type) = $this->parseConnectionName($name); // If we haven't created this connection, we'll create it based on the config // provided in the application. Once we've created the connections we will // set the "fetch mode" for PDO which determines the query return types. if ( ! isset($this->connections[$name])) { - $connection = $this->makeConnection($driver); - - $connection = $this->prepareReadWriteMode($connection, $type); + $connection = $this->makeConnection($driver) + ->setPdoForType($connection, $type); $this->connections[$name] = $this->prepare($connection); } @@ -77,6 +70,20 @@ public function connection($name = null) return $this->connections[$name]; } + /** + * Parse the connection into an array of the name and read / write type. + * + * @param string $name + * @return array + */ + protected function parseConnectionName($name) + { + $name = $name ?: $this->getDefaultConnection(); + + return Str::endsWith($name, ['::read', '::write']) + ? explode('::', $name, 2) : [$name, null]; + } + /** * Disconnect from the given database and remove from local cache. * @@ -221,7 +228,7 @@ protected function prepare(Connection $connection) * @param string $type * @return \Illuminate\Database\Connection */ - protected function prepareReadWriteMode($connection, $type = null) + protected function setPdoForType(Connection $connection, $type = null) { if ($type == 'read') { From 0e48af8825a3d7d20b84f0261a5902baffd2abe2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 13:20:17 -0500 Subject: [PATCH 371/577] Fix name. --- DatabaseManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index b6ccdb502..5e54c34e0 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -61,7 +61,7 @@ public function connection($name = null) // set the "fetch mode" for PDO which determines the query return types. if ( ! isset($this->connections[$name])) { - $connection = $this->makeConnection($driver) + $connection = $this->makeConnection($name) ->setPdoForType($connection, $type); $this->connections[$name] = $this->prepare($connection); From 2b8bec03af4a3d35f20de63021785f93937a804d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 13:38:27 -0500 Subject: [PATCH 372/577] Fix chaning. --- DatabaseManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 5e54c34e0..7801319b2 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -61,8 +61,9 @@ public function connection($name = null) // set the "fetch mode" for PDO which determines the query return types. if ( ! isset($this->connections[$name])) { - $connection = $this->makeConnection($name) - ->setPdoForType($connection, $type); + $connection = $this->makeConnection($name); + + $this->setPdoForType($connection, $type); $this->connections[$name] = $this->prepare($connection); } From 1a26e6ccc6f39b9bf923fb4a4e86e7178088f6ac Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 15 Jul 2014 10:37:08 +0100 Subject: [PATCH 373/577] Avoid using fully qualified names within the code --- Connection.php | 3 ++- Eloquent/Relations/BelongsToMany.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Connection.php b/Connection.php index 829070c20..741f5fd73 100755 --- a/Connection.php +++ b/Connection.php @@ -3,6 +3,7 @@ use PDO; use Closure; use DateTime; +use Illuminate\Events\Dispatcher; use Illuminate\Database\Query\Processors\Processor; use Doctrine\DBAL\Connection as DoctrineConnection; @@ -943,7 +944,7 @@ public function getEventDispatcher() * @param \Illuminate\Events\Dispatcher * @return void */ - public function setEventDispatcher(\Illuminate\Events\Dispatcher $events) + public function setEventDispatcher(Dispatcher $events) { $this->events = $events; } diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index beeb4a37c..7dd72a519 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -2,6 +2,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Expression; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -266,7 +267,7 @@ public function getRelationCountQuery(Builder $query, Builder $parent) */ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent) { - $query->select(new \Illuminate\Database\Query\Expression('count(*)')); + $query->select(new Expression('count(*)')); $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); @@ -274,7 +275,7 @@ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent $key = $this->wrap($this->getQualifiedParentKeyName()); - return $query->where($hash.'.'.$this->foreignKey, '=', new \Illuminate\Database\Query\Expression($key)); + return $query->where($hash.'.'.$this->foreignKey, '=', new Expression($key)); } /** From 9dd5685a48f6a3690d52f5c39864fdf0e934c789 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 15:17:54 -0500 Subject: [PATCH 374/577] Add fresh method to model. This method gets a fresh copy of the model using the ID from the existing instance. --- Eloquent/Model.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index eb81f897e..5356294fd 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -675,6 +675,19 @@ public static function findOrFail($id, $columns = array('*')) throw (new ModelNotFoundException)->setModel(get_called_class()); } + /** + * Reload a fresh model instance from the database. + * + * @param array $with + * @return $this + */ + public function fresh(array $with = array()) + { + $key = $this->getKeyName(); + + return $this->exists ? static::with($with)->where($key, $this->getKey())->first() : null; + } + /** * Eager load relations on the model. * From a9c0bb4c386b1c17c18a3eb709ed3f4b3bacdbe9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 16:07:41 -0500 Subject: [PATCH 375/577] Cleaning up a few things. --- Eloquent/Model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c2eaa6bbe..7390a6e62 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2684,7 +2684,7 @@ public function syncOriginalAttribute($attribute) /** * Determine if the model or given attribute(s) have been modified. * - * @param string|array|null $attributes + * @param array|string|null $attributes * @return bool */ public function isDirty($attributes = null) @@ -2694,10 +2694,10 @@ public function isDirty($attributes = null) if (is_null($attributes)) return count($dirty) > 0; if ( ! is_array($attributes)) $attributes = func_get_args(); - - foreach ($attributes as $attr) + + foreach ($attributes as $attribute) { - if (array_key_exists($attr, $dirty)) return true; + if (array_key_exists($attribute, $dirty)) return true; } return false; From 32f022fd0c63ae753eb55edfacf375cb0822dba9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Sep 2014 17:05:21 -0500 Subject: [PATCH 376/577] Rename some interfaces for consistency. --- Eloquent/Model.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 73ae516a6..98b450403 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -5,14 +5,14 @@ use Carbon\Carbon; use LogicException; use JsonSerializable; +use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Routing\UrlRoutable; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; -use Illuminate\Contracts\Support\JsonableInterface; -use Illuminate\Contracts\Support\ArrayableInterface; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -23,7 +23,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, UrlRoutable, JsonSerializable { +abstract class Model implements ArrayAccess, Arrayable, Jsonable, UrlRoutable, JsonSerializable { /** * The connection name for the model. @@ -2299,7 +2299,7 @@ public function relationsToArray() // If the values implements the Arrayable interface we can just call this // toArray method on the instances which will convert both models and // collections to their proper array form and we'll set the values. - if ($value instanceof ArrayableInterface) + if ($value instanceof Arrayable) { $relation = $value->toArray(); } @@ -2494,7 +2494,7 @@ protected function mutateAttributeForArray($key, $value) { $value = $this->mutateAttribute($key, $value); - return $value instanceof ArrayableInterface ? $value->toArray() : $value; + return $value instanceof Arrayable ? $value->toArray() : $value; } /** From 0156b09d19747488f2c56122ab46ba7147a27d93 Mon Sep 17 00:00:00 2001 From: Andy Zhang Date: Tue, 9 Sep 2014 09:26:31 +1000 Subject: [PATCH 377/577] Use morph class as morph type value. --- Eloquent/Relations/MorphPivot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index f9ffe63dd..d6c773f78 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -30,7 +30,7 @@ class MorphPivot extends Pivot { */ protected function setKeysForSaveQuery(Builder $query) { - $query->where($this->morphType, $this->getAttribute($this->morphType)); + $query->where($this->morphType, $this->morphClass); return parent::setKeysForSaveQuery($query); } @@ -44,7 +44,7 @@ public function delete() { $query = $this->getDeleteQuery(); - $query->where($this->morphType, $this->getAttribute($this->morphType)); + $query->where($this->morphType, $this->morphClass); return $query->delete(); } From b8aa5ced628fb16f1854f1ea936e549331410ba0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 08:34:58 -0500 Subject: [PATCH 378/577] Fix white space. --- Eloquent/Relations/MorphPivot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index d6c773f78..1f0d252a0 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -70,9 +70,9 @@ public function setMorphType($morphType) */ public function setMorphClass($morphClass) { - $this->morphClass = $morphClass; + $this->morphClass = $morphClass; - return $this; + return $this; } From b8333a7c8a3a9e9bbe92d31c965b59d113f0a98d Mon Sep 17 00:00:00 2001 From: Nadav Vinik Date: Wed, 10 Sep 2014 17:08:21 +0300 Subject: [PATCH 379/577] setKeyName in Eloquent/Model: Set the primary key for the model. --- Eloquent/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7390a6e62..e4b3c99c3 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1857,6 +1857,16 @@ public function getKeyName() return $this->primaryKey; } + /** + * Set the primary key for the model. + * + * @return void + */ + public function setKeyName($key) + { + $this->primaryKey = $key; + } + /** * Get the table qualified key name. * From 4c00de7e461a0128777ddb8d4ca643ee04cb2886 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 11:53:08 -0500 Subject: [PATCH 380/577] Clean up code. --- Query/Builder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 671c5a7bb..055a6311a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1504,10 +1504,10 @@ public function chunk($count, callable $callback) // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. - $return = call_user_func($callback, $results); - - if ($return === false) + if (call_user_func($callback, $results) === false) + { break; + } $page++; From eb5b7d8d8cda2641ed7c1cedd6cdf9cc79ddeda0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 12:07:31 -0500 Subject: [PATCH 381/577] Type hint contract. --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index b57952ea1..dcbc582ee 100755 --- a/Connection.php +++ b/Connection.php @@ -3,7 +3,7 @@ use PDO; use Closure; use DateTime; -use Illuminate\Events\Dispatcher; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Query\Processors\Processor; use Doctrine\DBAL\Connection as DoctrineConnection; From a930a2a1030ef781269aed11f615786df86974e1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 13:42:21 -0500 Subject: [PATCH 382/577] Clean up some array operations. --- Eloquent/Model.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 02d951af9..a1fa62c22 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1281,13 +1281,7 @@ public function addObservableEvents($observables) { $observables = is_array($observables) ? $observables : func_get_args(); - foreach ($observables as $observable) - { - if ( ! in_array($observable, $this->observables)) - { - $this->observables[] = $observable; - } - } + $this->observables = array_unique(array_merge($this->observables, $observables)); } /** @@ -1300,13 +1294,7 @@ public function removeObservableEvents($observables) { $observables = is_array($observables) ? $observables : func_get_args(); - foreach ($observables as $observable) - { - if (($index = array_search($observable, $this->observables)) !== false) - { - unset($this->observables[$index]); - } - } + $this->observables = array_diff($this->observables, $observables); } /** From 125d77c84006e43a9bb833ebcff2d4755ca5be92 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 13:58:00 -0500 Subject: [PATCH 383/577] Fix bug with read / write connection and inserting into Postgres. --- Connection.php | 30 +++++++++++++++++++++++--- Query/Processors/PostgresProcessor.php | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Connection.php b/Connection.php index 5840c7a24..1e4b13bd6 100755 --- a/Connection.php +++ b/Connection.php @@ -274,16 +274,29 @@ public function selectOne($query, $bindings = array()) * @param array $bindings * @return array */ - public function select($query, $bindings = array()) + public function selectFromWriteConnection($query, $bindings = array()) { - return $this->run($query, $bindings, function($me, $query, $bindings) + return $this->select($query, $bindings, false); + } + + /** + * Run a select statement against the database. + * + * @param string $query + * @param array $bindings + * @param bool $useReadPdo + * @return array + */ + public function select($query, $bindings = array(), $useReadPdo = true) + { + return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo) { if ($me->pretending()) return array(); // For select statements, we'll simply execute the query and return an array // of the database result set. Each element in the array will be a single // row from the database table, and will either be an array or objects. - $statement = $me->getReadPdo()->prepare($query); + $statement = $this->getPdoForSelect($useReadPdo)->prepare($query); $statement->execute($me->prepareBindings($bindings)); @@ -291,6 +304,17 @@ public function select($query, $bindings = array()) }); } + /** + * Get the PDO connection to use for a select query. + * + * @param bool $useReadPdo + * @return \PDO + */ + protected function getPdoForSelect($useReadPdo = true) + { + return $useReadPdo ? $this->getReadPdo() : $this->getPdo(); + } + /** * Run an insert statement against the database. * diff --git a/Query/Processors/PostgresProcessor.php b/Query/Processors/PostgresProcessor.php index 87ef3472e..c46f29846 100755 --- a/Query/Processors/PostgresProcessor.php +++ b/Query/Processors/PostgresProcessor.php @@ -15,7 +15,7 @@ class PostgresProcessor extends Processor { */ public function processInsertGetId(Builder $query, $sql, $values, $sequence = null) { - $results = $query->getConnection()->select($sql, $values); + $results = $query->getConnection()->selectFromWriteConnection($sql, $values); $sequence = $sequence ?: 'id'; From e61eeb2ebc9947785f181a29432e79ed8df2c45e Mon Sep 17 00:00:00 2001 From: sporchia Date: Wed, 10 Sep 2014 15:19:15 -0400 Subject: [PATCH 384/577] deleting from eloquent model will work with joins --- Query/Grammars/Grammar.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 5fe0931a3..d3efd735e 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -667,7 +667,16 @@ public function compileDelete(Builder $query) $where = is_array($query->wheres) ? $this->compileWheres($query) : ''; - return trim("delete from $table ".$where); + if (isset($query->joins)) + { + $joins = ' '.$this->compileJoins($query, $query->joins); + } + else + { + $joins = ''; + } + + return trim("delete $table from {$table}{$joins} $where"); } /** From a8b5ef4075585c3efc95e13f517abc212da9dc96 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 16:54:57 -0500 Subject: [PATCH 385/577] Cleaning up code. --- Console/Migrations/StatusCommand.php | 47 ++++++++++------------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php index 1e02d0a12..1bb4eed15 100644 --- a/Console/Migrations/StatusCommand.php +++ b/Console/Migrations/StatusCommand.php @@ -46,51 +46,36 @@ public function __construct(Migrator $migrator) */ public function fire() { - $this->migrator->setConnection($this->input->getOption('database')); - - $this->output->writeln(" Status Migration Name "); - $this->output->writeln("--------------------------------------------"); + if ( ! $this->migrator->repositoryExists()) + { + return $this->error('No migrations found.'); + } - $versions = $this->migrator->getRepository()->getRan(); - $migrationFiles = $this->migrator->getMigrationFiles($this->getMigrationPath()); + $ran = $this->migrator->getRepository()->getRan(); - foreach ($migrationFiles as $migration) + foreach ($this->getAllMigrationFiles() as $migration) { - if (in_array($migration, $versions)) - { - $status = " up "; - unset($versions[array_search($migration, $versions)]); - } - else - { - $status = " down "; - } - - $this->output->writeln("{$status} {$migration}"); + $migrations[] = in_array($migration, $ran) ? ['✔', $migration] : ['✗', $migration]; } - foreach ($versions as $missing) + if (count($migrations) > 0) { - $this->output->writeln(" up {$missing} *** MISSING ***"); + $this->table(['Ran?', 'Migration'], $migrations); + } + else + { + $this->error('No migrations found'); } } /** - * Get the console command options. + * Get all of the migration files. * * @return array */ - protected function getOptions() + protected function getAllMigrationFiles() { - return array( - array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null), - - array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), - - array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null), - - array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null), - ); + return $this->migrator->getMigrationFiles($this->laravel['path.database'].'/migrations'); } } From 8ccb04a4df39286c361ebc8c454378609ac8adda Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Sep 2014 16:55:29 -0500 Subject: [PATCH 386/577] Initiate variable. --- Console/Migrations/StatusCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php index 1bb4eed15..1664ef4f3 100644 --- a/Console/Migrations/StatusCommand.php +++ b/Console/Migrations/StatusCommand.php @@ -53,6 +53,8 @@ public function fire() $ran = $this->migrator->getRepository()->getRan(); + $migrations = []; + foreach ($this->getAllMigrationFiles() as $migration) { $migrations[] = in_array($migration, $ran) ? ['✔', $migration] : ['✗', $migration]; From 100d754d108ec4d0174cf36fb3c3b98f3feee064 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 11 Sep 2014 00:38:25 +0200 Subject: [PATCH 387/577] Rmove useless use in commands --- Console/Migrations/StatusCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php index 1664ef4f3..5344adaca 100644 --- a/Console/Migrations/StatusCommand.php +++ b/Console/Migrations/StatusCommand.php @@ -1,7 +1,6 @@ Date: Thu, 11 Sep 2014 08:45:04 -0300 Subject: [PATCH 388/577] Correct syntax when using the mysql command and comment after --- Schema/Grammars/MySqlGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 9dcef37cb..b97ef201b 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -11,7 +11,7 @@ class MySqlGrammar extends Grammar { * * @var array */ - protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'After', 'Comment'); + protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'Comment', 'After'); /** * The possible column serials From 522aedacb0870611ff9eee81a6975eca09bba8f2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 11 Sep 2014 09:01:25 -0500 Subject: [PATCH 389/577] Revert "deleting from eloquent model will work with joins" --- Query/Grammars/Grammar.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index d3efd735e..5fe0931a3 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -667,16 +667,7 @@ public function compileDelete(Builder $query) $where = is_array($query->wheres) ? $this->compileWheres($query) : ''; - if (isset($query->joins)) - { - $joins = ' '.$this->compileJoins($query, $query->joins); - } - else - { - $joins = ''; - } - - return trim("delete $table from {$table}{$joins} $where"); + return trim("delete from $table ".$where); } /** From b66a7173ca6a81de3b2ccbd84372bee8624215f1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 11 Sep 2014 09:10:29 -0500 Subject: [PATCH 390/577] Enable deletes with joins in MySQL. Tests. --- Query/Grammars/MySqlGrammar.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Query/Grammars/MySqlGrammar.php b/Query/Grammars/MySqlGrammar.php index 4c3fdc773..b068e2b0d 100755 --- a/Query/Grammars/MySqlGrammar.php +++ b/Query/Grammars/MySqlGrammar.php @@ -92,6 +92,28 @@ public function compileUpdate(Builder $query, $values) return rtrim($sql); } + /** + * Compile a delete statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + public function compileDelete(Builder $query) + { + $table = $this->wrapTable($query->from); + + $where = is_array($query->wheres) ? $this->compileWheres($query) : ''; + + if (isset($query->joins)) + { + $joins = ' '.$this->compileJoins($query, $query->joins); + + return trim("delete $table from {$table}{$joins} $where"); + } + + return trim("delete from $table $where"); + } + /** * Wrap a single string in keyword identifiers. * From f2da95d00fb1790e2ce490e73aee4370d84da3c6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 11 Sep 2014 20:16:42 +0100 Subject: [PATCH 391/577] [5.0] Bump the master to 5.0 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2539357a5..dbf91f61c 100755 --- a/composer.json +++ b/composer.json @@ -10,16 +10,16 @@ ], "require": { "php": ">=5.4.0", - "illuminate/container": "4.3.*", - "illuminate/contracts": "4.3.*", - "illuminate/support": "4.3.*", + "illuminate/container": "5.0.*", + "illuminate/contracts": "5.0.*", + "illuminate/support": "5.0.*", "nesbot/carbon": "~1.0" }, "require-dev": { - "illuminate/console": "4.3.*", - "illuminate/filesystem": "4.3.*", - "illuminate/pagination": "4.3.*", - "illuminate/support": "4.3.*" + "illuminate/console": "5.0.*", + "illuminate/filesystem": "5.0.*", + "illuminate/pagination": "5.0.*", + "illuminate/support": "5.0.*" }, "autoload": { "psr-4": { @@ -28,7 +28,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "5.0-dev" } }, "minimum-stability": "dev" From 8c0f8218dcd1239bcf0d0ca2caab488bcbcac012 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 12 Sep 2014 14:13:07 -0500 Subject: [PATCH 392/577] working on cleaning up doctrine code. --- Schema/Blueprint.php | 6 +- Schema/Grammars/Grammar.php | 118 ++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 66a37bcae..173ac1799 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -847,7 +847,8 @@ public function getCommands() */ public function addedColumns() { - return array_filter($this->columns, function($column) { + return array_filter($this->columns, function($column) + { return !$column->change; }); } @@ -859,7 +860,8 @@ public function addedColumns() */ public function changedColumns() { - return array_filter($this->columns, function($column) { + return array_filter($this->columns, function($column) + { return !!$column->change; }); } diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index f7d259034..a31952199 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -1,12 +1,12 @@ addedColumns() : $blueprint->changedColumns() as $column) + foreach ($change ? $blueprint->changedColumns() : $blueprint->addedColumns() as $column) { // Each of the column types have their own compiler functions which are tasked // with turning the column definition into its SQL format for this platform @@ -272,9 +272,11 @@ protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $sch } /** - * @param Blueprint $blueprint - * @param Fluent $command - * @param Connection $connection + * Compile a change column command into a series of SQL statements. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @param \Illuminate\Database\Connection $connection * @return array */ public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) @@ -283,7 +285,7 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection $tableDiff = $this->getChangedDiff($blueprint, $schema); - if($tableDiff !== false) + if ($tableDiff !== false) { return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); } @@ -292,97 +294,93 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection } /** - * @param Blueprint $blueprint - * @param SchemaManager $schema - * @return bool|TableDiff + * Get the Doctrine table difference for the given changes. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @return \Doctrine\DBAL\Schema\TableDiff|bool */ protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema) { - $tableName = $this->getTablePrefix().$blueprint->getTable(); - - $table = $schema->listTableDetails($tableName); + $table = $schema->listTableDetails($this->getTablePrefix().$blueprint->getTable()); - $tableClone = $this->getChangedColumnsClone($blueprint, $table); - - $comparator = new Comparator; - - $tableDiff = $comparator->diffTable($table, $tableClone); - - return $tableDiff; + return (new Comparator)->diffTable($table, $this->getChangedColumnsClone($blueprint, $table)); } /** * Clone Doctrine table and update column definitions based on blueprint. * - * @param Blueprint $blueprint - * @param Table $table - * @return Table + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Doctrine\DBAL\Schema\Table $table + * @return \Doctrine\DBAL\Schema\TableDiff */ protected function getChangedColumnsClone(Blueprint $blueprint, Table $table) { - $tableClone = clone $table; + $table = clone $table; - foreach($blueprint->changedColumns() as $fluentColumn) + foreach($blueprint->changedColumns() as $fluent) { - $tableClone = $tableClone->changeColumn($fluentColumn['name'], array('type' => Type::getType($fluentColumn['type']))); - - $column = $tableClone->getColumn($fluentColumn['name']); + $table = $table->changeColumn( + $fluent['name'], array('type' => Type::getType($fluent['type'])) + ); - //Skipable boolean attributes must be reset - $column->setNotnull(true); - $column->setUnsigned(false); + $column = $table->getColumn($fluent['name']); - foreach ($fluentColumn->getAttributes() as $key => $value) + foreach ($fluent->getAttributes() as $key => $value) { + $option = $this->mapFluenOptionToDoctrine($key); - $option = $this->getFluentAttributeDoctrineColumnOptionName($key); - - //Behavior of notnull is opposite of nullable - if($option == 'notnull') $value = !$value; - - if( ! is_null($option) ) + if ( ! is_null($option)) { - $method = 'set'.ucfirst($option); - - if (method_exists($column, $method)) + if (method_exists($column, $method = 'set'.ucfirst($option))) { - $column->{$method}($value); + $column->{$method}($this->mapFluentValueToDoctrine($option, $value)); } } } } - return $tableClone; + return $table; } /** - * Returns comparable doctrine option for fluent attribute name. + * Get the matching Doctrine value for a given Fluent attribute. * - * @param $attribute + * @param string $option + * @param mixed $value + * @return mixed + */ + protected function mapFluentValueToDoctrine($option, $value) + { + return $option == 'notnull' ? ! $value : $value; + } + + /** + * Get the matching Doctrine option for a given Fluent attribute name. + * + * @param string $attribute * @return string */ - protected function getFluentAttributeDoctrineColumnOptionName($attribute) { - $option = null; + protected function mapFluenOptionToDoctrine($attribute) + { switch($attribute) { case 'type': case 'name': - //No option for type and name - break; + return; + case 'nullable': - $option = 'notnull'; - break; + return 'notnull'; + case 'total': - $option = 'precision'; - break; + return 'precision'; + case 'places': - $option = 'scale'; - break; + return 'scale'; + default: - $option = $attribute; - break; + return $attribute; } - return $option; } } From e252dae46e20d52bba6d35f27f05f18bce4e77c8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 12 Sep 2014 14:58:00 -0500 Subject: [PATCH 393/577] Continue cleaning up column changer. --- Schema/Blueprint.php | 10 ++--- Schema/Grammars/Grammar.php | 90 ++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 26 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 173ac1799..ac9712752 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -103,14 +103,12 @@ public function toSql(Connection $connection, Grammar $grammar) */ protected function addImpliedCommands() { - //compileAdd command to add columns - if (count($this->addedColumns()) > 0 && ! $this->creating()) + if (count($this->getAddedColumns()) > 0 && ! $this->creating()) { array_unshift($this->commands, $this->createCommand('add')); } - //compileChange command to modify columns - if (count($this->changedColumns()) > 0 && ! $this->creating()) + if (count($this->getChangedColumns()) > 0 && ! $this->creating()) { array_unshift($this->commands, $this->createCommand('change')); } @@ -845,7 +843,7 @@ public function getCommands() * * @return array */ - public function addedColumns() + public function getAddedColumns() { return array_filter($this->columns, function($column) { @@ -858,7 +856,7 @@ public function addedColumns() * * @return array */ - public function changedColumns() + public function getChangedColumns() { return array_filter($this->columns, function($column) { diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index a31952199..c36b9291e 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -119,7 +119,7 @@ protected function getColumns(Blueprint $blueprint, $change = false) { $columns = array(); - foreach ($change ? $blueprint->changedColumns() : $blueprint->addedColumns() as $column) + foreach ($change ? $blueprint->getChangedColumns() : $blueprint->getAddedColumns() as $column) { // Each of the column types have their own compiler functions which are tasked // with turning the column definition into its SQL format for this platform @@ -304,33 +304,30 @@ protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema) { $table = $schema->listTableDetails($this->getTablePrefix().$blueprint->getTable()); - return (new Comparator)->diffTable($table, $this->getChangedColumnsClone($blueprint, $table)); + return (new Comparator)->diffTable($table, $this->getTableWithColumnChanges($blueprint, $table)); } /** - * Clone Doctrine table and update column definitions based on blueprint. + * Get a copy of the given Doctrine table after making the column changes. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Doctrine\DBAL\Schema\Table $table * @return \Doctrine\DBAL\Schema\TableDiff */ - protected function getChangedColumnsClone(Blueprint $blueprint, Table $table) + protected function getTableWithColumnChanges(Blueprint $blueprint, Table $table) { $table = clone $table; - foreach($blueprint->changedColumns() as $fluent) + foreach($blueprint->getChangedColumns() as $fluent) { - $table = $table->changeColumn( - $fluent['name'], array('type' => Type::getType($fluent['type'])) - ); - - $column = $table->getColumn($fluent['name']); + $column = $this->getDoctrineColumnForChange($table, $fluent); + // Here we will spin through each fluent column definition and map it to the proper + // Doctrine column definitions, which is necessasry because Laravel and Doctrine + // use some different terminology for various column attributes on the tables. foreach ($fluent->getAttributes() as $key => $value) { - $option = $this->mapFluenOptionToDoctrine($key); - - if ( ! is_null($option)) + if ( ! is_null($option = $this->mapFluentOptionToDoctrine($key))) { if (method_exists($column, $method = 'set'.ucfirst($option))) { @@ -344,15 +341,56 @@ protected function getChangedColumnsClone(Blueprint $blueprint, Table $table) } /** - * Get the matching Doctrine value for a given Fluent attribute. + * Get the Doctrine column instance for a column change. * - * @param string $option - * @param mixed $value - * @return mixed + * @param \Doctrine\DBAL\Schema\Table $table + * @param \Illuminate\Support\Fluent $fluent + * @return \Doctrine\DBAL\Schema\Column */ - protected function mapFluentValueToDoctrine($option, $value) + protected function getDoctrineColumnForChange(Table $table, Fluent $fluent) { - return $option == 'notnull' ? ! $value : $value; + return $table->changeColumn( + $fluent['name'], $this->getDoctrineColumnChangeOptions($fluent) + )->getColumn($fluent['name']); + } + + /** + * Get the Doctrine column change options. + * + * @param \Illuminate\Support\Fluent $fluent + * @return array + */ + protected function getDoctrineColumnChangeOptions(Fluent $fluent) + { + $options = ['type' => Type::getType($fluent['type'])]; + + if (in_array($fluent['type'], ['text', 'mediumText', 'longText'])) + { + $options['length'] = $this->calculateDoctrineTextLength($fluent['type']); + } + + return $options; + } + + /** + * Calculate the proper column length to force the Doctrine text type. + * + * @param string $type + * @return int + */ + protected function calculateDoctrineTextLength($type) + { + switch ($type) + { + case 'mediumText': + return 65535 + 1; + + case 'longText': + return 16777215 + 1; + + default: + return 255 + 1; + } } /** @@ -361,7 +399,7 @@ protected function mapFluentValueToDoctrine($option, $value) * @param string $attribute * @return string */ - protected function mapFluenOptionToDoctrine($attribute) + protected function mapFluentOptionToDoctrine($attribute) { switch($attribute) { @@ -383,4 +421,16 @@ protected function mapFluenOptionToDoctrine($attribute) } } + /** + * Get the matching Doctrine value for a given Fluent attribute. + * + * @param string $option + * @param mixed $value + * @return mixed + */ + protected function mapFluentValueToDoctrine($option, $value) + { + return $option == 'notnull' ? ! $value : $value; + } + } From 92087a3d674b43dec63ee5572d1c6803275a26a5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 12 Sep 2014 15:17:22 -0500 Subject: [PATCH 394/577] Tweak column mapping a bit. --- Schema/Grammars/MySqlGrammar.php | 2 +- Schema/Grammars/PostgresGrammar.php | 8 ++++---- Schema/Grammars/SQLiteGrammar.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index da377ac97..3b71e4378 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -386,7 +386,7 @@ protected function typeSmallInteger(Fluent $column) */ protected function typeFloat(Fluent $column) { - return "float({$column->total}, {$column->places})"; + return $this->typeDouble($column); } /** diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index 76916170c..aedfed0f1 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -340,7 +340,7 @@ protected function typeSmallInteger(Fluent $column) */ protected function typeFloat(Fluent $column) { - return 'real'; + return $this->typeDouble($column); } /** @@ -408,7 +408,7 @@ protected function typeDate(Fluent $column) */ protected function typeDateTime(Fluent $column) { - return 'timestamp'; + return 'timestamp(0) without time zone'; } /** @@ -419,7 +419,7 @@ protected function typeDateTime(Fluent $column) */ protected function typeTime(Fluent $column) { - return 'time'; + return 'time(0) without time zone'; } /** @@ -430,7 +430,7 @@ protected function typeTime(Fluent $column) */ protected function typeTimestamp(Fluent $column) { - return 'timestamp'; + return 'timestamp(0) without time zone'; } /** diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index 01be7b10d..391f6b525 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -426,7 +426,7 @@ protected function typeDouble(Fluent $column) */ protected function typeDecimal(Fluent $column) { - return 'float'; + return 'numeric'; } /** From 5817dd4085bb274374dc2ed3df8d1c963ad84837 Mon Sep 17 00:00:00 2001 From: Stidges Date: Mon, 15 Sep 2014 23:42:23 +0200 Subject: [PATCH 395/577] Fix attach for pivot tables that only have either a created_at or updated_at timestamp. --- Eloquent/Relations/BelongsToMany.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 7dd72a519..adf17df5a 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -326,6 +326,17 @@ protected function getAliasedPivotColumns() return array_unique($columns); } + /** + * Determine whether the given column is defined as a pivot column. + * + * @param string $column + * @return bool + */ + protected function hasPivotColumn($column) + { + return in_array($column, $this->pivotColumns); + } + /** * Set the join clause for the relation query. * @@ -718,7 +729,7 @@ protected function createAttachRecords($ids, array $attributes) { $records = array(); - $timed = in_array($this->createdAt(), $this->pivotColumns); + $timed = ($this->hasPivotColumn('created_at') || $this->hasPivotColumn('updated_at')); // To create the attachment records, we will simply spin through the IDs given // and create a new record to insert for each ID. Each ID may actually be a @@ -807,9 +818,15 @@ protected function setTimestampsOnAttach(array $record, $exists = false) { $fresh = $this->parent->freshTimestamp(); - if ( ! $exists) $record[$this->createdAt()] = $fresh; + if ( ! $exists && $this->hasPivotColumn('created_at')) + { + $record[$this->createdAt()] = $fresh; + } - $record[$this->updatedAt()] = $fresh; + if ($this->hasPivotColumn('updated_at')) + { + $record[$this->updatedAt()] = $fresh; + } return $record; } From cf518f14d5ac0503a0c1cf34a972d1b9a25412c2 Mon Sep 17 00:00:00 2001 From: Stidges Date: Mon, 15 Sep 2014 23:48:15 +0200 Subject: [PATCH 396/577] Change explicit references to 'created_at' and 'updated_at' to 'createdAt' and 'updatedAt' method calls --- Eloquent/Relations/BelongsToMany.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index adf17df5a..2368d7d20 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -729,7 +729,7 @@ protected function createAttachRecords($ids, array $attributes) { $records = array(); - $timed = ($this->hasPivotColumn('created_at') || $this->hasPivotColumn('updated_at')); + $timed = ($this->hasPivotColumn($this->createdAt()) || $this->hasPivotColumn($this->updatedAt())); // To create the attachment records, we will simply spin through the IDs given // and create a new record to insert for each ID. Each ID may actually be a @@ -818,12 +818,12 @@ protected function setTimestampsOnAttach(array $record, $exists = false) { $fresh = $this->parent->freshTimestamp(); - if ( ! $exists && $this->hasPivotColumn('created_at')) + if ( ! $exists && $this->hasPivotColumn($this->createdAt())) { $record[$this->createdAt()] = $fresh; } - if ($this->hasPivotColumn('updated_at')) + if ($this->hasPivotColumn($this->updatedAt())) { $record[$this->updatedAt()] = $fresh; } From 7136ef286ff31fdfcd021442a0b47ebae1b8ba93 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Sat, 1 Feb 2014 08:49:43 +0100 Subject: [PATCH 397/577] don't allow access of relationship properties via snake_case --- Eloquent/Model.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 80f9bcdfe..15eba385e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2433,11 +2433,9 @@ public function getAttribute($key) // If the "attribute" exists as a method on the model, we will just assume // it is a relationship and will load and return results from the query // and hydrate the relationship's value on the "relationships" array. - $camelKey = camel_case($key); - - if (method_exists($this, $camelKey)) + if (method_exists($this, $key)) { - return $this->getRelationshipFromMethod($key, $camelKey); + return $this->getRelationshipFromMethod($key); } } @@ -2487,15 +2485,14 @@ protected function getAttributeFromArray($key) /** * Get a relationship value from a method. * - * @param string $key - * @param string $camelKey + * @param string $method * @return mixed * * @throws \LogicException */ - protected function getRelationshipFromMethod($key, $camelKey) + protected function getRelationshipFromMethod($method) { - $relations = $this->$camelKey(); + $relations = $this->$method(); if ( ! $relations instanceof Relation) { @@ -2503,7 +2500,7 @@ protected function getRelationshipFromMethod($key, $camelKey) . 'Illuminate\Database\Eloquent\Relations\Relation'); } - return $this->relations[$key] = $relations->getResults(); + return $this->relations[$method] = $relations->getResults(); } /** From 97a24cc1baa1129079a11cf2006103f2062c994a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 19 Sep 2014 21:09:50 -0500 Subject: [PATCH 398/577] Working on QueueableEntities. --- DatabaseServiceProvider.php | 15 +++++++++++++++ Eloquent/Model.php | 13 ++++++++++++- Eloquent/QueueEntityResolver.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Eloquent/QueueEntityResolver.php diff --git a/DatabaseServiceProvider.php b/DatabaseServiceProvider.php index 492642225..8ea963663 100755 --- a/DatabaseServiceProvider.php +++ b/DatabaseServiceProvider.php @@ -25,6 +25,8 @@ public function boot() */ public function register() { + $this->registerQueueableEntityResolver(); + // The connection factory is used to create the actual connection instances on // the database. We will inject the factory into the manager so that it may // make the connections while they are actually needed and not of before. @@ -42,4 +44,17 @@ public function register() }); } + /** + * Register the queueable entity resolver implementation. + * + * @return void + */ + protected function registerQueueableEntityResolver() + { + $this->app->bindShared('Illuminate\Contracts\Queue\EntityResolver', function() + { + return new Eloquent\QueueEntityResolver; + }); + } + } diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 80f9bcdfe..33f3ca970 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Routing\UrlRoutable; +use Illuminate\Contracts\Queue\QueueableEntity; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -23,7 +24,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, Arrayable, Jsonable, UrlRoutable, JsonSerializable { +abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable { /** * The connection name for the model. @@ -1906,6 +1907,16 @@ public function getKey() return $this->getAttribute($this->getKeyName()); } + /** + * Get the queueable identity for the entity. + * + * @var mixed + */ + public function getQueueableId() + { + return $this->getKey(); + } + /** * Get the primary key for the model. * diff --git a/Eloquent/QueueEntityResolver.php b/Eloquent/QueueEntityResolver.php new file mode 100644 index 000000000..8a784fb64 --- /dev/null +++ b/Eloquent/QueueEntityResolver.php @@ -0,0 +1,29 @@ +find($id); + + if ($instance) + { + return $instance; + } + else + { + throw new EntityNotFoundException($type, $id); + } + } + +} From 35d943554bb7f53c341eb34a56713ae502459a41 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 20 Sep 2014 15:19:26 +0200 Subject: [PATCH 399/577] Remove useless else...return --- Connectors/ConnectionFactory.php | 12 ++++-------- DatabaseManager.php | 6 ++---- Eloquent/Builder.php | 12 ++++-------- Eloquent/Model.php | 6 ++---- Eloquent/Relations/BelongsToMany.php | 6 ++---- Eloquent/SoftDeletingTrait.php | 6 ++---- Query/Builder.php | 12 ++++-------- Query/Grammars/PostgresGrammar.php | 6 ++---- Query/Grammars/SqlServerGrammar.php | 6 ++---- Schema/Builder.php | 6 ++---- Schema/Grammars/MySqlGrammar.php | 6 ++---- 11 files changed, 28 insertions(+), 56 deletions(-) diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index 2e63ec6f0..17df20cf5 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -42,10 +42,8 @@ public function make(array $config, $name = null) { return $this->createReadWriteConnection($config); } - else - { - return $this->createSingleConnection($config); - } + + return $this->createSingleConnection($config); } /** @@ -126,10 +124,8 @@ protected function getReadWriteConfig(array $config, $type) { return $config[$type][array_rand($config[$type])]; } - else - { - return $config[$type]; - } + + return $config[$type]; } /** diff --git a/DatabaseManager.php b/DatabaseManager.php index 7801319b2..e30d5d377 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -126,10 +126,8 @@ public function reconnect($name = null) { return $this->connection($name); } - else - { - return $this->refreshPdoConnections($name); - } + + return $this->refreshPdoConnections($name); } /** diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index f103fadbc..67e06720a 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -242,10 +242,8 @@ public function paginate($perPage = null, $columns = array('*')) { return $this->groupedPaginate($paginator, $perPage, $columns); } - else - { - return $this->ungroupedPaginate($paginator, $perPage, $columns); - } + + return $this->ungroupedPaginate($paginator, $perPage, $columns); } /** @@ -374,10 +372,8 @@ public function delete() { return call_user_func($this->onDelete, $this); } - else - { - return $this->query->delete(); - } + + return $this->query->delete(); } /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a1fa62c22..e9c24211d 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1626,10 +1626,8 @@ protected function getKeyForSaveQuery() { return $this->original[$this->getKeyName()]; } - else - { - return $this->getAttribute($this->getKeyName()); - } + + return $this->getAttribute($this->getKeyName()); } /** diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 7dd72a519..9abddb016 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -766,10 +766,8 @@ protected function getAttachId($key, $value, array $attributes) { return array($key, array_merge($value, $attributes)); } - else - { - return array($value, $attributes); - } + + return array($value, $attributes); } /** diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index de7f95b8b..e54523bd2 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -44,10 +44,8 @@ protected function performDeleteOnModel() { $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete(); } - else - { - return $this->runSoftDelete(); - } + + return $this->runSoftDelete(); } /** diff --git a/Query/Builder.php b/Query/Builder.php index e13f52b3d..022b6a031 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1385,10 +1385,8 @@ public function getCached($columns = array('*')) { return $cache->rememberForever($key, $callback); } - else - { - return $cache->remember($key, $minutes, $callback); - } + + return $cache->remember($key, $minutes, $callback); } /** @@ -1552,10 +1550,8 @@ public function paginate($perPage = 15, $columns = array('*')) { return $this->groupedPaginate($paginator, $perPage, $columns); } - else - { - return $this->ungroupedPaginate($paginator, $perPage, $columns); - } + + return $this->ungroupedPaginate($paginator, $perPage, $columns); } /** diff --git a/Query/Grammars/PostgresGrammar.php b/Query/Grammars/PostgresGrammar.php index 0894e1424..7a8df9c4c 100755 --- a/Query/Grammars/PostgresGrammar.php +++ b/Query/Grammars/PostgresGrammar.php @@ -117,10 +117,8 @@ protected function compileUpdateWheres(Builder $query) { return 'where '.$this->removeLeadingBoolean($joinWhere); } - else - { - return $baseWhere.' '.$joinWhere; - } + + return $baseWhere.' '.$joinWhere; } /** diff --git a/Query/Grammars/SqlServerGrammar.php b/Query/Grammars/SqlServerGrammar.php index f6faaf868..24fd428ec 100755 --- a/Query/Grammars/SqlServerGrammar.php +++ b/Query/Grammars/SqlServerGrammar.php @@ -77,10 +77,8 @@ protected function compileFrom(Builder $query, $table) { return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)'; } - else - { - return $from; - } + + return $from; } /** diff --git a/Schema/Builder.php b/Schema/Builder.php index c40c2e23a..707909b3d 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -182,10 +182,8 @@ protected function createBlueprint($table, Closure $callback = null) { return call_user_func($this->resolver, $table, $callback); } - else - { - return new Blueprint($table, $callback); - } + + return new Blueprint($table, $callback); } /** diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index da377ac97..90210ab53 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -401,10 +401,8 @@ protected function typeDouble(Fluent $column) { return "double({$column->total}, {$column->places})"; } - else - { - return 'double'; - } + + return 'double'; } /** From 2e2fadd8ee19cfbcf1cd95edeea1c078898b6fd8 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 20 Sep 2014 15:59:08 +0200 Subject: [PATCH 400/577] Global formatting fix --- Eloquent/Builder.php | 2 +- Eloquent/Collection.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index f103fadbc..a91e85ad2 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -96,7 +96,7 @@ public function findMany($id, $columns = array('*')) $this->query->whereIn($this->model->getQualifiedKeyName(), $id); return $this->get($columns); - } + } /** * Find a model by its primary key or throw an exception. diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index 4301c2cda..dc520e56d 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -215,9 +215,9 @@ public function only($keys) */ public function except($keys) { - $dictionary = array_except($this->getDictionary(), $keys); + $dictionary = array_except($this->getDictionary(), $keys); - return new static(array_values($dictionary)); + return new static(array_values($dictionary)); } /** From 86a23290e962018305b257f357c6ff8c9766a1e2 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 21 Sep 2014 18:05:47 +0200 Subject: [PATCH 401/577] Remaining useless else --- Connectors/SqlServerConnector.php | 8 +++----- Eloquent/Builder.php | 6 ++---- Eloquent/Relations/BelongsToMany.php | 8 +++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index 1d81fe572..b6660752f 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -48,12 +48,10 @@ protected function getDsn(array $config) { return "dblib:host={$host}{$port};dbname={$database}"; } - else - { - $dbName = $database != '' ? ";Database={$database}" : ''; - return "sqlsrv:Server={$host}{$port}{$dbName}"; - } + $dbName = $database != '' ? ";Database={$database}" : ''; + + return "sqlsrv:Server={$host}{$port}{$dbName}"; } /** diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 36d1981cf..2cea79d7c 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -904,10 +904,8 @@ public function __call($method, $parameters) { return $this->callScope($scope, $parameters); } - else - { - $result = call_user_func_array(array($this->query, $method), $parameters); - } + + $result = call_user_func_array(array($this->query, $method), $parameters); return in_array($method, $this->passthru) ? $result : $this; } diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 9abddb016..e7b8e5d08 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -250,12 +250,10 @@ public function getRelationCountQuery(Builder $query, Builder $parent) { return $this->getRelationCountQueryForSelfJoin($query, $parent); } - else - { - $this->setJoin($query); - return parent::getRelationCountQuery($query, $parent); - } + $this->setJoin($query); + + return parent::getRelationCountQuery($query, $parent); } /** From 376440f5f344b9a91880f41c3fda10b4fac48b86 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 21 Sep 2014 18:08:59 +0200 Subject: [PATCH 402/577] Add missing new line --- Eloquent/Relations/BelongsToMany.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 9abddb016..f79fef610 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -663,6 +663,7 @@ protected function attachNew(array $records, array $current, $touch = true) $changes['updated'][] = (int) $id; } } + return $changes; } From d6304941be1a65d77f69419e0a6a512a86742bb0 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Sun, 21 Sep 2014 18:19:47 -0500 Subject: [PATCH 403/577] Initialize array in SQLiteGrammar.php --- Schema/Grammars/SQLiteGrammar.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index 01be7b10d..dfda9af4d 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -148,6 +148,8 @@ public function compileAdd(Blueprint $blueprint, Fluent $command) $columns = $this->prefixArray('add column', $this->getColumns($blueprint)); + $statements = array(); + foreach ($columns as $column) { $statements[] = 'alter table '.$table.' '.$column; From 9d6afd0587a2c58c8fb8ee4c363c2c69ca2ef9ab Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 24 Sep 2014 10:31:55 +0200 Subject: [PATCH 404/577] Remove unused code --- Schema/Grammars/SqlServerGrammar.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 79042771b..3e32903cb 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -157,8 +157,6 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command) */ public function compileDropPrimary(Blueprint $blueprint, Fluent $command) { - $table = $blueprint->getTable(); - $table = $this->wrapTable($blueprint); return "alter table {$table} drop constraint {$command->index}"; From 5a7c8db4520eff5f7035f77206d8444d3acb7af0 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 25 Sep 2014 14:06:05 +0200 Subject: [PATCH 405/577] Remove last duplicate unset --- Eloquent/Model.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e9c24211d..e052ea0f6 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -3046,9 +3046,7 @@ public function __isset($key) */ public function __unset($key) { - unset($this->attributes[$key]); - - unset($this->relations[$key]); + unset($this->attributes[$key], $this->relations[$key]); } /** From 904c4ce373ee7da9dd72543a4a9800685a651d72 Mon Sep 17 00:00:00 2001 From: Bishop Bettini Date: Thu, 25 Sep 2014 23:07:26 -0400 Subject: [PATCH 406/577] Query grammar should not explode segments on alias --- Grammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grammar.php b/Grammar.php index 153c15223..d7ed02b79 100755 --- a/Grammar.php +++ b/Grammar.php @@ -50,7 +50,7 @@ public function wrap($value) { $segments = explode(' ', $value); - return $this->wrap($segments[0]).' as '.$this->wrap($segments[2]); + return $this->wrap($segments[0]).' as '.$this->wrapValue($segments[2]); } $wrapped = array(); From 89c059a6b20242cbcd2a3ae6fe8bfc5152542f70 Mon Sep 17 00:00:00 2001 From: Andreas Lutro Date: Fri, 26 Sep 2014 13:36:20 +0200 Subject: [PATCH 407/577] ease saving of models without updating timestamps --- Eloquent/Model.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e9c24211d..20a5860b1 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1420,7 +1420,7 @@ public function save(array $options = array()) // clause to only update this model. Otherwise, we'll just insert them. if ($this->exists) { - $saved = $this->performUpdate($query); + $saved = $this->performUpdate($query, $options); } // If the model is brand new, we'll insert it into our database and set the @@ -1428,7 +1428,7 @@ public function save(array $options = array()) // which is typically an auto-increment value managed by the database. else { - $saved = $this->performInsert($query); + $saved = $this->performInsert($query, $options); } if ($saved) $this->finishSave($options); @@ -1457,7 +1457,7 @@ protected function finishSave(array $options) * @param \Illuminate\Database\Eloquent\Builder $query * @return bool|null */ - protected function performUpdate(Builder $query) + protected function performUpdate(Builder $query, array $options) { $dirty = $this->getDirty(); @@ -1474,7 +1474,7 @@ protected function performUpdate(Builder $query) // First we need to create a fresh query instance and touch the creation and // update timestamp on the model which are maintained by us for developer // convenience. Then we will just continue saving the model instances. - if ($this->timestamps) + if ($this->timestamps && array_get($options, 'timestamps', true)) { $this->updateTimestamps(); } @@ -1501,14 +1501,14 @@ protected function performUpdate(Builder $query) * @param \Illuminate\Database\Eloquent\Builder $query * @return bool */ - protected function performInsert(Builder $query) + protected function performInsert(Builder $query, array $options) { if ($this->fireModelEvent('creating') === false) return false; // First we'll need to create a fresh query instance and touch the creation and // update timestamps on this model, which are maintained by us for developer // convenience. After, we will just continue saving these model instances. - if ($this->timestamps) + if ($this->timestamps && array_get($options, 'timestamps', true)) { $this->updateTimestamps(); } From 2e8eab7cfc26425eace9e584ab4df96ae38662fa Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 26 Sep 2014 16:40:57 +0200 Subject: [PATCH 408/577] Remove useless $app arguments in bindShared --- MigrationServiceProvider.php | 2 +- SeedServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 0b2faafcb..f7f0fccab 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -145,7 +145,7 @@ protected function registerResetCommand() */ protected function registerRefreshCommand() { - $this->app->bindShared('command.migrate.refresh', function($app) + $this->app->bindShared('command.migrate.refresh', function() { return new RefreshCommand; }); diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index be9291352..7b5e6d44c 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -21,7 +21,7 @@ public function register() { $this->registerSeedCommand(); - $this->app->bindShared('seeder', function($app) + $this->app->bindShared('seeder', function() { return new Seeder; }); From 247ee85ed9f5e2d7e1b0eb79a514fb6c75f22df7 Mon Sep 17 00:00:00 2001 From: manavo Date: Fri, 26 Sep 2014 22:04:01 +0100 Subject: [PATCH 409/577] Only propagate the touchOwners call if a relationship exists --- Eloquent/Model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e9c24211d..bb194660f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1566,7 +1566,10 @@ public function touchOwners() { $this->$relation()->touch(); - $this->$relation->touchOwners(); + if ( ! is_null($this->$relation)) + { + $this->$relation->touchOwners(); + } } } From 352f68c6c05138346eecf66369d0a208a1d7f51d Mon Sep 17 00:00:00 2001 From: Joe Green Date: Thu, 25 Sep 2014 17:12:48 +0100 Subject: [PATCH 410/577] fix memory leak in QueryBuilder/JoinBuilder --- Query/Builder.php | 4 ++-- Query/Grammars/Grammar.php | 5 +++++ Query/JoinClause.php | 20 +++++++++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 022b6a031..1cb8c6460 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -279,7 +279,7 @@ public function join($table, $one, $operator = null, $two = null, $type = 'inner // one condition, so we'll add the join and call a Closure with the query. if ($one instanceof Closure) { - $this->joins[] = new JoinClause($this, $type, $table); + $this->joins[] = new JoinClause($type, $table); call_user_func($one, end($this->joins)); } @@ -289,7 +289,7 @@ public function join($table, $one, $operator = null, $two = null, $type = 'inner // this simple join clauses attached to it. There is not a join callback. else { - $join = new JoinClause($this, $type, $table); + $join = new JoinClause($type, $table); $this->joins[] = $join->on( $one, $operator, $two, 'and', $where diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 5fe0931a3..da8bcc967 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -142,6 +142,11 @@ protected function compileJoins(Builder $query, $joins) $clauses[] = $this->compileJoinConstraint($clause); } + foreach ($join->bindings as $binding) + { + $query->addBinding($binding, 'join'); + } + // Once we have constructed the clauses, we'll need to take the boolean connector // off of the first clause as it obviously will not be required on that clause // because it leads the rest of the clauses, thus not requiring any boolean. diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 837f4635c..3cca966bd 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -2,13 +2,6 @@ class JoinClause { - /** - * The query builder instance. - * - * @var \Illuminate\Database\Query\Builder - */ - public $query; - /** * The type of join being performed. * @@ -30,18 +23,23 @@ class JoinClause { */ public $clauses = array(); + /** + * The "on" bindings for the join. + * + * @var array + */ + public $bindings = array(); + /** * Create a new join clause instance. * - * @param \Illuminate\Database\Query\Builder $query * @param string $type * @param string $table * @return void */ - public function __construct(Builder $query, $type, $table) + public function __construct($type, $table) { $this->type = $type; - $this->query = $query; $this->table = $table; } @@ -59,7 +57,7 @@ public function on($first, $operator, $second, $boolean = 'and', $where = false) { $this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where'); - if ($where) $this->query->addBinding($second, 'join'); + if ($where) $this->bindings[] = $second; return $this; } From 16660d4a3a72ef3fbe51f9fe19afb65000067931 Mon Sep 17 00:00:00 2001 From: Vinicius Moraes Date: Fri, 26 Sep 2014 22:17:06 +0000 Subject: [PATCH 411/577] Adding the regex operators for PostgreSQL --- Query/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Query/Builder.php b/Query/Builder.php index 6aa16ac18..d870a812e 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -178,6 +178,7 @@ class Builder { 'like', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', 'rlike', 'regexp', 'not regexp', + '~', '~*', '!~', '!~*' ); /** From e74225879767ff5e605d021be82205ce30f1bf8b Mon Sep 17 00:00:00 2001 From: Vinicius Moraes Date: Sat, 27 Sep 2014 01:26:01 +0000 Subject: [PATCH 412/577] Fixing the indentation problem --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index d870a812e..a816e1043 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -178,7 +178,7 @@ class Builder { 'like', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', 'rlike', 'regexp', 'not regexp', - '~', '~*', '!~', '!~*' + '~', '~*', '!~', '!~*', ); /** From 02f990736e435090f3e43eb8cd441c2bc8ce0a38 Mon Sep 17 00:00:00 2001 From: benti Date: Sat, 27 Sep 2014 20:13:47 +0200 Subject: [PATCH 413/577] bugfix: orHaving does not work when used as first having condition. --- Query/Grammars/Grammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index da8bcc967..a7be847c6 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -461,7 +461,7 @@ protected function compileHavings(Builder $query, $havings) { $sql = implode(' ', array_map(array($this, 'compileHaving'), $havings)); - return 'having '.preg_replace('/and /', '', $sql, 1); + return 'having '.preg_replace('/and |or /', '', $sql, 1); } /** From 147d64fcea87f5e9bc9b5c8b7e298c07bb8a1abe Mon Sep 17 00:00:00 2001 From: Caleb Fidecaro Date: Sun, 28 Sep 2014 11:17:40 +1300 Subject: [PATCH 414/577] Update ScopeInterface w/ tests --- Eloquent/ScopeInterface.php | 7 +++++-- Eloquent/SoftDeletingScope.php | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Eloquent/ScopeInterface.php b/Eloquent/ScopeInterface.php index b0a93a90c..7cc13494f 100644 --- a/Eloquent/ScopeInterface.php +++ b/Eloquent/ScopeInterface.php @@ -6,16 +6,19 @@ interface ScopeInterface { * Apply the scope to a given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model * @return void */ - public function apply(Builder $builder); + public function apply(Builder $builder, Model $model); /** * Remove the scope from the given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model + * * @return void */ - public function remove(Builder $builder); + public function remove(Builder $builder, Model $model); } diff --git a/Eloquent/SoftDeletingScope.php b/Eloquent/SoftDeletingScope.php index f5d1f4816..c6903cdd4 100644 --- a/Eloquent/SoftDeletingScope.php +++ b/Eloquent/SoftDeletingScope.php @@ -13,12 +13,11 @@ class SoftDeletingScope implements ScopeInterface { * Apply the scope to a given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model * @return void */ - public function apply(Builder $builder) + public function apply(Builder $builder, Model $model) { - $model = $builder->getModel(); - $builder->whereNull($model->getQualifiedDeletedAtColumn()); $this->extend($builder); @@ -28,11 +27,12 @@ public function apply(Builder $builder) * Remove the scope from the given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model * @return void */ - public function remove(Builder $builder) + public function remove(Builder $builder, Model $model) { - $column = $builder->getModel()->getQualifiedDeletedAtColumn(); + $column = $model->getQualifiedDeletedAtColumn(); $query = $builder->getQuery(); @@ -113,7 +113,7 @@ protected function addWithTrashed(Builder $builder) { $builder->macro('withTrashed', function(Builder $builder) { - $this->remove($builder); + $this->remove($builder, $builder->getModel()); return $builder; }); @@ -129,9 +129,11 @@ protected function addOnlyTrashed(Builder $builder) { $builder->macro('onlyTrashed', function(Builder $builder) { - $this->remove($builder); + $model = $builder->getModel(); + + $this->remove($builder, $model); - $builder->getQuery()->whereNotNull($builder->getModel()->getQualifiedDeletedAtColumn()); + $builder->getQuery()->whereNotNull($model->getQualifiedDeletedAtColumn()); return $builder; }); From e8da7fe129cf1f322e094b2504749b8cd15e790e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 28 Sep 2014 18:56:24 +0100 Subject: [PATCH 415/577] Fixed the manager names in the capsule docblocks --- Capsule/Manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 529c13bc7..408e5630a 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -157,7 +157,7 @@ public function setFetchMode($fetchMode) /** * Get the database manager instance. * - * @return \Illuminate\Database\Manager + * @return \Illuminate\Database\DatabaseManager */ public function getDatabaseManager() { @@ -191,7 +191,7 @@ public function setEventDispatcher(Dispatcher $dispatcher) /** * Get the current cache manager instance. * - * @return \Illuminate\Cache\Manager + * @return \Illuminate\Cache\CacheManager */ public function getCacheManager() { From 4342d6bb5cb7868eb8512953a6ec0afd5190b1f7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 30 Sep 2014 08:42:10 -0500 Subject: [PATCH 416/577] normalizing line ending apparently. --- DatabaseServiceProvider.php | 120 ++++----- MigrationServiceProvider.php | 456 +++++++++++++++++------------------ 2 files changed, 288 insertions(+), 288 deletions(-) diff --git a/DatabaseServiceProvider.php b/DatabaseServiceProvider.php index 8ea963663..f6a127393 100755 --- a/DatabaseServiceProvider.php +++ b/DatabaseServiceProvider.php @@ -1,60 +1,60 @@ -app['db']); - - Model::setEventDispatcher($this->app['events']); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->registerQueueableEntityResolver(); - - // The connection factory is used to create the actual connection instances on - // the database. We will inject the factory into the manager so that it may - // make the connections while they are actually needed and not of before. - $this->app->bindShared('db.factory', function($app) - { - return new ConnectionFactory($app); - }); - - // The database manager is used to resolve various connections, since multiple - // connections might be managed. It also implements the connection resolver - // interface which may be used by other components requiring connections. - $this->app->bindShared('db', function($app) - { - return new DatabaseManager($app, $app['db.factory']); - }); - } - - /** - * Register the queueable entity resolver implementation. - * - * @return void - */ - protected function registerQueueableEntityResolver() - { - $this->app->bindShared('Illuminate\Contracts\Queue\EntityResolver', function() - { - return new Eloquent\QueueEntityResolver; - }); - } - -} +app['db']); + + Model::setEventDispatcher($this->app['events']); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerQueueableEntityResolver(); + + // The connection factory is used to create the actual connection instances on + // the database. We will inject the factory into the manager so that it may + // make the connections while they are actually needed and not of before. + $this->app->bindShared('db.factory', function($app) + { + return new ConnectionFactory($app); + }); + + // The database manager is used to resolve various connections, since multiple + // connections might be managed. It also implements the connection resolver + // interface which may be used by other components requiring connections. + $this->app->bindShared('db', function($app) + { + return new DatabaseManager($app, $app['db.factory']); + }); + } + + /** + * Register the queueable entity resolver implementation. + * + * @return void + */ + protected function registerQueueableEntityResolver() + { + $this->app->bindShared('Illuminate\Contracts\Queue\EntityResolver', function() + { + return new Eloquent\QueueEntityResolver; + }); + } + +} diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 7d0a2d6c1..4328fa0f0 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -1,228 +1,228 @@ -registerRepository(); - - // Once we have registered the migrator instance we will go ahead and register - // all of the migration related commands that are used by the "Artisan" CLI - // so that they may be easily accessed for registering with the consoles. - $this->registerMigrator(); - - $this->registerCommands(); - } - - /** - * Register the migration repository service. - * - * @return void - */ - protected function registerRepository() - { - $this->app->bindShared('migration.repository', function($app) - { - $table = $app['config']['database.migrations']; - - return new DatabaseMigrationRepository($app['db'], $table); - }); - } - - /** - * Register the migrator service. - * - * @return void - */ - protected function registerMigrator() - { - // The migrator is responsible for actually running and rollback the migration - // files in the application. We'll pass in our database connection resolver - // so the migrator can resolve any of these connections when it needs to. - $this->app->bindShared('migrator', function($app) - { - $repository = $app['migration.repository']; - - return new Migrator($repository, $app['db'], $app['files']); - }); - } - - /** - * Register all of the migration commands. - * - * @return void - */ - protected function registerCommands() - { - $commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make', 'Status'); - - // We'll simply spin through the list of commands that are migration related - // and register each one of them with an application container. They will - // be resolved in the Artisan start file and registered on the console. - foreach ($commands as $command) - { - $this->{'register'.$command.'Command'}(); - } - - // Once the commands are registered in the application IoC container we will - // register them with the Artisan start event so that these are available - // when the Artisan application actually starts up and is getting used. - $this->commands( - 'command.migrate', 'command.migrate.make', - 'command.migrate.install', 'command.migrate.rollback', - 'command.migrate.reset', 'command.migrate.refresh', - 'command.migrate.status' - ); - } - - /** - * Register the "migrate" migration command. - * - * @return void - */ - protected function registerMigrateCommand() - { - $this->app->bindShared('command.migrate', function($app) - { - $packagePath = $app['path.base'].'/vendor'; - - return new MigrateCommand($app['migrator'], $packagePath); - }); - } - - /** - * Register the "rollback" migration command. - * - * @return void - */ - protected function registerRollbackCommand() - { - $this->app->bindShared('command.migrate.rollback', function($app) - { - return new RollbackCommand($app['migrator']); - }); - } - - /** - * Register the "reset" migration command. - * - * @return void - */ - protected function registerResetCommand() - { - $this->app->bindShared('command.migrate.reset', function($app) - { - return new ResetCommand($app['migrator']); - }); - } - - /** - * Register the "refresh" migration command. - * - * @return void - */ - protected function registerRefreshCommand() - { - $this->app->bindShared('command.migrate.refresh', function() - { - return new RefreshCommand; - }); - } - - protected function registerStatusCommand() - { - $this->app->bindShared('command.migrate.status', function($app) - { - return new StatusCommand($app['migrator']); - }); - } - - /** - * Register the "install" migration command. - * - * @return void - */ - protected function registerInstallCommand() - { - $this->app->bindShared('command.migrate.install', function($app) - { - return new InstallCommand($app['migration.repository']); - }); - } - - /** - * Register the "make" migration command. - * - * @return void - */ - protected function registerMakeCommand() - { - $this->registerCreator(); - - $this->app->bindShared('command.migrate.make', function($app) - { - // Once we have the migration creator registered, we will create the command - // and inject the creator. The creator is responsible for the actual file - // creation of the migrations, and may be extended by these developers. - $creator = $app['migration.creator']; - - $packagePath = $app['path.base'].'/vendor'; - - return new MigrateMakeCommand($creator, $packagePath); - }); - } - - /** - * Register the migration creator. - * - * @return void - */ - protected function registerCreator() - { - $this->app->bindShared('migration.creator', function($app) - { - return new MigrationCreator($app['files']); - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array( - 'migrator', 'migration.repository', 'command.migrate', - 'command.migrate.rollback', 'command.migrate.reset', - 'command.migrate.refresh', 'command.migrate.install', - 'command.migrate.status', 'migration.creator', - 'command.migrate.make', - ); - } - -} +registerRepository(); + + // Once we have registered the migrator instance we will go ahead and register + // all of the migration related commands that are used by the "Artisan" CLI + // so that they may be easily accessed for registering with the consoles. + $this->registerMigrator(); + + $this->registerCommands(); + } + + /** + * Register the migration repository service. + * + * @return void + */ + protected function registerRepository() + { + $this->app->bindShared('migration.repository', function($app) + { + $table = $app['config']['database.migrations']; + + return new DatabaseMigrationRepository($app['db'], $table); + }); + } + + /** + * Register the migrator service. + * + * @return void + */ + protected function registerMigrator() + { + // The migrator is responsible for actually running and rollback the migration + // files in the application. We'll pass in our database connection resolver + // so the migrator can resolve any of these connections when it needs to. + $this->app->bindShared('migrator', function($app) + { + $repository = $app['migration.repository']; + + return new Migrator($repository, $app['db'], $app['files']); + }); + } + + /** + * Register all of the migration commands. + * + * @return void + */ + protected function registerCommands() + { + $commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make', 'Status'); + + // We'll simply spin through the list of commands that are migration related + // and register each one of them with an application container. They will + // be resolved in the Artisan start file and registered on the console. + foreach ($commands as $command) + { + $this->{'register'.$command.'Command'}(); + } + + // Once the commands are registered in the application IoC container we will + // register them with the Artisan start event so that these are available + // when the Artisan application actually starts up and is getting used. + $this->commands( + 'command.migrate', 'command.migrate.make', + 'command.migrate.install', 'command.migrate.rollback', + 'command.migrate.reset', 'command.migrate.refresh', + 'command.migrate.status' + ); + } + + /** + * Register the "migrate" migration command. + * + * @return void + */ + protected function registerMigrateCommand() + { + $this->app->bindShared('command.migrate', function($app) + { + $packagePath = $app['path.base'].'/vendor'; + + return new MigrateCommand($app['migrator'], $packagePath); + }); + } + + /** + * Register the "rollback" migration command. + * + * @return void + */ + protected function registerRollbackCommand() + { + $this->app->bindShared('command.migrate.rollback', function($app) + { + return new RollbackCommand($app['migrator']); + }); + } + + /** + * Register the "reset" migration command. + * + * @return void + */ + protected function registerResetCommand() + { + $this->app->bindShared('command.migrate.reset', function($app) + { + return new ResetCommand($app['migrator']); + }); + } + + /** + * Register the "refresh" migration command. + * + * @return void + */ + protected function registerRefreshCommand() + { + $this->app->bindShared('command.migrate.refresh', function() + { + return new RefreshCommand; + }); + } + + protected function registerStatusCommand() + { + $this->app->bindShared('command.migrate.status', function($app) + { + return new StatusCommand($app['migrator']); + }); + } + + /** + * Register the "install" migration command. + * + * @return void + */ + protected function registerInstallCommand() + { + $this->app->bindShared('command.migrate.install', function($app) + { + return new InstallCommand($app['migration.repository']); + }); + } + + /** + * Register the "make" migration command. + * + * @return void + */ + protected function registerMakeCommand() + { + $this->registerCreator(); + + $this->app->bindShared('command.migrate.make', function($app) + { + // Once we have the migration creator registered, we will create the command + // and inject the creator. The creator is responsible for the actual file + // creation of the migrations, and may be extended by these developers. + $creator = $app['migration.creator']; + + $packagePath = $app['path.base'].'/vendor'; + + return new MigrateMakeCommand($creator, $packagePath); + }); + } + + /** + * Register the migration creator. + * + * @return void + */ + protected function registerCreator() + { + $this->app->bindShared('migration.creator', function($app) + { + return new MigrationCreator($app['files']); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array( + 'migrator', 'migration.repository', 'command.migrate', + 'command.migrate.rollback', 'command.migrate.reset', + 'command.migrate.refresh', 'command.migrate.install', + 'command.migrate.status', 'migration.creator', + 'command.migrate.make', + ); + } + +} From bba3bc5ead1c4eb8726e3fa788c6d9e316427824 Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Tue, 16 Sep 2014 16:58:30 +0100 Subject: [PATCH 417/577] Pivot table child queries respect where conditions added through wherePivot() --- Eloquent/Relations/BelongsToMany.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 7dd72a519..52887cf02 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -43,6 +43,13 @@ class BelongsToMany extends Relation { */ protected $pivotColumns = array(); + /** + * Any pivot table restrictions. + * + * @var array + */ + protected $pivotWheres = []; + /** * Create a new has many relationship instance. * @@ -85,6 +92,8 @@ public function getResults() */ public function wherePivot($column, $operator = null, $value = null, $boolean = 'and') { + $this->pivotWheres[] = func_get_args(); + return $this->where($this->table.'.'.$column, $operator, $value, $boolean); } @@ -888,6 +897,11 @@ protected function newPivotQuery() { $query = $this->newPivotStatement(); + foreach ($this->pivotWheres as $whereArgs) + { + call_user_func_array([$query, 'where'], $whereArgs); + } + return $query->where($this->foreignKey, $this->parent->getKey()); } @@ -909,11 +923,7 @@ public function newPivotStatement() */ public function newPivotStatementForId($id) { - $pivot = $this->newPivotStatement(); - - $key = $this->parent->getKey(); - - return $pivot->where($this->foreignKey, $key)->where($this->otherKey, $id); + return $this->newPivotQuery()->where($this->otherKey, $id); } /** From 4f995d89e95ebd00ecb00be91db9a144e3d31fa7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 1 Oct 2014 20:10:26 -0500 Subject: [PATCH 418/577] Disable query log by default. --- Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index b0366a837..3311f1877 100755 --- a/Connection.php +++ b/Connection.php @@ -98,7 +98,7 @@ class Connection implements ConnectionInterface { * * @var bool */ - protected $loggingQueries = true; + protected $loggingQueries = false; /** * Indicates if the connection is in a "dry run". From abb5db2e7cbdc5d388e9b1448b69cec7d577c2ca Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Thu, 2 Oct 2014 12:31:41 +0300 Subject: [PATCH 419/577] Fix broken transaction logic when PDO changes --- Connection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Connection.php b/Connection.php index 1e4b13bd6..4a9933d04 100755 --- a/Connection.php +++ b/Connection.php @@ -831,6 +831,8 @@ public function getReadPdo() */ public function setPdo($pdo) { + if ($this->transactions >= 1) throw new \RuntimeException("Attempt to change PDO inside running transaction"); + $this->pdo = $pdo; return $this; From d8305ac8a618676e18c8c4dc8ef868df7374cfb3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Oct 2014 13:45:44 -0500 Subject: [PATCH 420/577] Protect developers from using forceDelete when not using trait. --- Eloquent/Model.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ca38ce2e0..d5d575f70 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1112,6 +1112,18 @@ public function delete() } } + /** + * Force a hard delete on a soft deleted model. + * + * This method protects developers from running forceDelete when trait is missing. + * + * @return void + */ + public function forceDelete() + { + return $this->delete(); + } + /** * Perform the actual delete query on this model instance. * From 6c0c0b5ec3dabead93915b3b318ee550ee5fc93d Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Sun, 5 Oct 2014 17:05:53 -0400 Subject: [PATCH 421/577] Set morphs directly --- Eloquent/Relations/MorphOneOrMany.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index 9c6ae7e2d..4a20351ed 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -101,14 +101,12 @@ public function save(Model $model) */ public function create(array $attributes) { - $foreign = $this->getForeignAttributesForCreate(); + $instance = $this->related->newInstance($attributes); // When saving a polymorphic relationship, we need to set not only the foreign // key, but also the foreign key type, which is typically the class name of // the parent model. This makes the polymorphic item unique in the table. - $attributes = array_merge($attributes, $foreign); - - $instance = $this->related->newInstance($attributes); + $this->setForeignAttributesForCreate($instance); $instance->save(); @@ -116,17 +114,16 @@ public function create(array $attributes) } /** - * Get the foreign ID and type for creating a related model. + * Set the foreign ID and type for creating a related model. * - * @return array + * @param \Illuminate\Database\Eloquent\Model $model + * @return void */ - protected function getForeignAttributesForCreate() + protected function setForeignAttributesForCreate(Model $model) { - $foreign = array($this->getPlainForeignKey() => $this->getParentKey()); - - $foreign[last(explode('.', $this->morphType))] = $this->morphClass; + $model->{$this->getPlainForeignKey()} = $this->getParentKey(); - return $foreign; + $model->{last(explode('.', $this->morphType))} = $this->morphClass; } /** From 4867d18e83d36621fa12e308ac0e8322a94c5e39 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 7 Oct 2014 16:01:04 -0500 Subject: [PATCH 422/577] Remove caching and pagination from database. --- Capsule/Manager.php | 25 -- Connection.php | 66 ------ DatabaseManager.php | 15 -- Eloquent/Builder.php | 80 ------- Eloquent/Model.php | 28 --- Eloquent/Relations/BelongsToMany.php | 21 -- Eloquent/Relations/HasManyThrough.php | 16 -- Query/Builder.php | 321 -------------------------- README.md | 3 - composer.json | 2 - 10 files changed, 577 deletions(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index 0a800581e..ef72cf75e 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -2,7 +2,6 @@ use PDO; use Illuminate\Support\Fluent; -use Illuminate\Cache\CacheManager; use Illuminate\Container\Container; use Illuminate\Database\DatabaseManager; use Illuminate\Contracts\Events\Dispatcher; @@ -189,30 +188,6 @@ public function setEventDispatcher(Dispatcher $dispatcher) $this->container->instance('events', $dispatcher); } - /** - * Get the current cache manager instance. - * - * @return \Illuminate\Cache\CacheManager - */ - public function getCacheManager() - { - if ($this->container->bound('cache')) - { - return $this->container['cache']; - } - } - - /** - * Set the cache manager to be used by connections. - * - * @param \Illuminate\Cache\CacheManager $cache - * @return void - */ - public function setCacheManager(CacheManager $cache) - { - $this->container->instance('cache', $cache); - } - /** * Dynamically pass methods to the default connection. * diff --git a/Connection.php b/Connection.php index 3311f1877..7fde6f68d 100755 --- a/Connection.php +++ b/Connection.php @@ -58,20 +58,6 @@ class Connection implements ConnectionInterface { */ protected $events; - /** - * The paginator environment instance. - * - * @var \Illuminate\Pagination\Paginator - */ - protected $paginator; - - /** - * The cache manager instance. - * - * @var \Illuminate\Cache\CacheManager - */ - protected $cache; - /** * The default fetch mode of the connection. * @@ -977,58 +963,6 @@ public function setEventDispatcher(Dispatcher $events) $this->events = $events; } - /** - * Get the paginator environment instance. - * - * @return \Illuminate\Pagination\Factory - */ - public function getPaginator() - { - if ($this->paginator instanceof Closure) - { - $this->paginator = call_user_func($this->paginator); - } - - return $this->paginator; - } - - /** - * Set the pagination environment instance. - * - * @param \Illuminate\Pagination\Factory|\Closure $paginator - * @return void - */ - public function setPaginator($paginator) - { - $this->paginator = $paginator; - } - - /** - * Get the cache manager instance. - * - * @return \Illuminate\Cache\CacheManager - */ - public function getCacheManager() - { - if ($this->cache instanceof Closure) - { - $this->cache = call_user_func($this->cache); - } - - return $this->cache; - } - - /** - * Set the cache manager instance on the connection. - * - * @param \Illuminate\Cache\CacheManager|\Closure $cache - * @return void - */ - public function setCacheManager($cache) - { - $this->cache = $cache; - } - /** * Determine if the connection in a "dry run". * diff --git a/DatabaseManager.php b/DatabaseManager.php index e30d5d377..ddade604e 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -191,23 +191,8 @@ protected function prepare(Connection $connection) $connection->setEventDispatcher($this->app['events']); } - // The database connection can also utilize a cache manager instance when cache - // functionality is used on queries, which provides an expressive interface - // to caching both fluent queries and Eloquent queries that are executed. $app = $this->app; - $connection->setCacheManager(function() use ($app) - { - return $app['cache']; - }); - - // We will setup a Closure to resolve the paginator instance on the connection - // since the Paginator isn't used on every request and needs quite a few of - // our dependencies. It'll be more efficient to lazily resolve instances. - $connection->setPaginator(function() use ($app) - { - return $app['paginator']; - }); // Here we'll set a reconnector callback. This reconnector can be any callable // so we will set a Closure to reconnect from this manager with the name of diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 2cea79d7c..28324d6ba 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -225,86 +225,6 @@ public function lists($column, $key = null) return $results; } - /** - * Get a paginator for the "select" statement. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function paginate($perPage = null, $columns = array('*')) - { - $perPage = $perPage ?: $this->model->getPerPage(); - - $paginator = $this->query->getConnection()->getPaginator(); - - if (isset($this->query->groups)) - { - return $this->groupedPaginate($paginator, $perPage, $columns); - } - - return $this->ungroupedPaginate($paginator, $perPage, $columns); - } - - /** - * Get a paginator for a grouped statement. - * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - protected function groupedPaginate($paginator, $perPage, $columns) - { - $results = $this->get($columns)->all(); - - return $this->query->buildRawPaginator($paginator, $results, $perPage); - } - - /** - * Get a paginator for an ungrouped statement. - * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - protected function ungroupedPaginate($paginator, $perPage, $columns) - { - $total = $this->query->getPaginationCount(); - - // Once we have the paginator we need to set the limit and offset values for - // the query so we can get the properly paginated items. Once we have an - // array of items we can create the paginator instances for the items. - $page = $paginator->getCurrentPage($total); - - $this->query->forPage($page, $perPage); - - return $paginator->make($this->get($columns)->all(), $total, $perPage); - } - - /** - * Get a paginator only supporting simple next and previous links. - * - * This is more efficient on larger data-sets, etc. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function simplePaginate($perPage = null, $columns = array('*')) - { - $paginator = $this->query->getConnection()->getPaginator(); - - $page = $paginator->getCurrentPage(); - - $perPage = $perPage ?: $this->model->getPerPage(); - - $this->query->skip(($page - 1) * $perPage)->take($perPage + 1); - - return $paginator->make($this->get($columns)->all(), $perPage); - } - /** * Update a record in the database. * diff --git a/Eloquent/Model.php b/Eloquent/Model.php index fc16e704e..845d9e1cc 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -47,13 +47,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ protected $primaryKey = 'id'; - /** - * The number of models to return for pagination. - * - * @var int - */ - protected $perPage = 15; - /** * Indicates if the IDs are auto-incrementing. * @@ -2017,27 +2010,6 @@ public function getMorphClass() return $this->morphClass ?: get_class($this); } - /** - * Get the number of models to return per page. - * - * @return int - */ - public function getPerPage() - { - return $this->perPage; - } - - /** - * Set the number of models to return per page. - * - * @param int $perPage - * @return void - */ - public function setPerPage($perPage) - { - $this->perPage = $perPage; - } - /** * Get the default foreign key name for the model. * diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 8814b028d..32e1b7c0c 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -159,27 +159,6 @@ public function get($columns = array('*')) return $this->related->newCollection($models); } - /** - * Get a paginator for the "select" statement. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function paginate($perPage = null, $columns = array('*')) - { - $this->query->addSelect($this->getSelectColumns($columns)); - - // When paginating results, we need to add the pivot columns to the query and - // then hydrate into the pivot objects once the results have been gathered - // from the database since this isn't performed by the Eloquent builder. - $pager = $this->query->paginate($perPage, $columns); - - $this->hydratePivotRelation($pager->getItems()); - - return $pager; - } - /** * Hydrate the pivot table relationship on the models. * diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index f378ce660..f5431a1d7 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -233,22 +233,6 @@ protected function getSelectColumns(array $columns = array('*')) return array_merge($columns, array($this->parent->getTable().'.'.$this->firstKey)); } - /** - * Get a paginator for the "select" statement. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function paginate($perPage = null, $columns = array('*')) - { - $this->query->addSelect($this->getSelectColumns($columns)); - - $pager = $this->query->paginate($perPage, $columns); - - return $pager; - } - /** * Get the key name of the parent model. * diff --git a/Query/Builder.php b/Query/Builder.php index b3b4b31bb..5abb5b953 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -133,41 +133,6 @@ class Builder { */ public $lock; - /** - * The backups of fields while doing a pagination count. - * - * @var array - */ - protected $backups = array(); - - /** - * The key that should be used when caching the query. - * - * @var string - */ - protected $cacheKey; - - /** - * The number of minutes to cache the query. - * - * @var int - */ - protected $cacheMinutes; - - /** - * The tags for the query cache. - * - * @var array - */ - protected $cacheTags; - - /** - * The cache driver to be used. - * - * @var string - */ - protected $cacheDriver; - /** * All of the available clause operators. * @@ -1276,57 +1241,6 @@ public function toSql() return $this->grammar->compileSelect($this); } - /** - * Indicate that the query results should be cached. - * - * @param \DateTime|int $minutes - * @param string $key - * @return $this - */ - public function remember($minutes, $key = null) - { - list($this->cacheMinutes, $this->cacheKey) = array($minutes, $key); - - return $this; - } - - /** - * Indicate that the query results should be cached forever. - * - * @param string $key - * @return \Illuminate\Database\Query\Builder|static - */ - public function rememberForever($key = null) - { - return $this->remember(-1, $key); - } - - /** - * Indicate that the results, if cached, should use the given cache tags. - * - * @param array|mixed $cacheTags - * @return $this - */ - public function cacheTags($cacheTags) - { - $this->cacheTags = $cacheTags; - - return $this; - } - - /** - * Indicate that the results, if cached, should use the given cache driver. - * - * @param string $cacheDriver - * @return $this - */ - public function cacheDriver($cacheDriver) - { - $this->cacheDriver = $cacheDriver; - - return $this; - } - /** * Execute a query for a single record by ID. * @@ -1373,8 +1287,6 @@ public function first($columns = array('*')) */ public function get($columns = array('*')) { - if ( ! is_null($this->cacheMinutes)) return $this->getCached($columns); - return $this->getFresh($columns); } @@ -1401,91 +1313,6 @@ protected function runSelect() return $this->connection->select($this->toSql(), $this->getBindings()); } - /** - * Execute the query as a cached "select" statement. - * - * @param array $columns - * @return array - */ - public function getCached($columns = array('*')) - { - if (is_null($this->columns)) $this->columns = $columns; - - // If the query is requested to be cached, we will cache it using a unique key - // for this database connection and query statement, including the bindings - // that are used on this query, providing great convenience when caching. - list($key, $minutes) = $this->getCacheInfo(); - - $cache = $this->getCache(); - - $callback = $this->getCacheCallback($columns); - - // If the "minutes" value is less than zero, we will use that as the indicator - // that the value should be remembered values should be stored indefinitely - // and if we have minutes we will use the typical remember function here. - if ($minutes < 0) - { - return $cache->rememberForever($key, $callback); - } - - return $cache->remember($key, $minutes, $callback); - } - - /** - * Get the cache object with tags assigned, if applicable. - * - * @return \Illuminate\Cache\CacheManager - */ - protected function getCache() - { - $cache = $this->connection->getCacheManager()->driver($this->cacheDriver); - - return $this->cacheTags ? $cache->tags($this->cacheTags) : $cache; - } - - /** - * Get the cache key and cache minutes as an array. - * - * @return array - */ - protected function getCacheInfo() - { - return array($this->getCacheKey(), $this->cacheMinutes); - } - - /** - * Get a unique cache key for the complete query. - * - * @return string - */ - public function getCacheKey() - { - return $this->cacheKey ?: $this->generateCacheKey(); - } - - /** - * Generate the unique cache key for the query. - * - * @return string - */ - public function generateCacheKey() - { - $name = $this->connection->getName(); - - return md5($name.$this->toSql().serialize($this->getBindings())); - } - - /** - * Get the Closure callback used when caching queries. - * - * @param array $columns - * @return \Closure - */ - protected function getCacheCallback($columns) - { - return function() use ($columns) { return $this->getFresh($columns); }; - } - /** * Chunk the results of the query. * @@ -1580,154 +1407,6 @@ public function implode($column, $glue = null) return implode($glue, $this->lists($column)); } - /** - * Get a paginator for the "select" statement. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function paginate($perPage = 15, $columns = array('*')) - { - $paginator = $this->connection->getPaginator(); - - if (isset($this->groups)) - { - return $this->groupedPaginate($paginator, $perPage, $columns); - } - - return $this->ungroupedPaginate($paginator, $perPage, $columns); - } - - /** - * Create a paginator for a grouped pagination statement. - * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - protected function groupedPaginate($paginator, $perPage, $columns) - { - $results = $this->get($columns); - - return $this->buildRawPaginator($paginator, $results, $perPage); - } - - /** - * Build a paginator instance from a raw result array. - * - * @param \Illuminate\Pagination\Factory $paginator - * @param array $results - * @param int $perPage - * @return \Illuminate\Pagination\Paginator - */ - public function buildRawPaginator($paginator, $results, $perPage) - { - // For queries which have a group by, we will actually retrieve the entire set - // of rows from the table and "slice" them via PHP. This is inefficient and - // the developer must be aware of this behavior; however, it's an option. - $start = ($paginator->getCurrentPage() - 1) * $perPage; - - $sliced = array_slice($results, $start, $perPage); - - return $paginator->make($sliced, count($results), $perPage); - } - - /** - * Create a paginator for an un-grouped pagination statement. - * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - protected function ungroupedPaginate($paginator, $perPage, $columns) - { - $total = $this->getPaginationCount(); - - // Once we have the total number of records to be paginated, we can grab the - // current page and the result array. Then we are ready to create a brand - // new Paginator instances for the results which will create the links. - $page = $paginator->getCurrentPage($total); - - $results = $this->forPage($page, $perPage)->get($columns); - - return $paginator->make($results, $total, $perPage); - } - - /** - * Get the count of the total records for pagination. - * - * @return int - */ - public function getPaginationCount() - { - $this->backupFieldsForCount(); - - // Because some database engines may throw errors if we leave the ordering - // statements on the query, we will "back them up" and remove them from - // the query. Once we have the count we will put them back onto this. - $total = $this->count(); - - $this->restoreFieldsForCount(); - - return $total; - } - - /** - * Get a paginator only supporting simple next and previous links. - * - * This is more efficient on larger data-sets, etc. - * - * @param int $perPage - * @param array $columns - * @return \Illuminate\Pagination\Paginator - */ - public function simplePaginate($perPage = null, $columns = array('*')) - { - $paginator = $this->connection->getPaginator(); - - $page = $paginator->getCurrentPage(); - - $perPage = $perPage ?: $this->model->getPerPage(); - - $this->skip(($page - 1) * $perPage)->take($perPage + 1); - - return $paginator->make($this->get($columns), $perPage); - } - - /** - * Backup certain fields for a pagination count. - * - * @return void - */ - protected function backupFieldsForCount() - { - foreach (array('orders', 'limit', 'offset') as $field) - { - $this->backups[$field] = $this->{$field}; - - $this->{$field} = null; - } - - } - - /** - * Restore certain fields for a pagination count. - * - * @return void - */ - protected function restoreFieldsForCount() - { - foreach (array('orders', 'limit', 'offset') as $field) - { - $this->{$field} = $this->backups[$field]; - } - - $this->backups = array(); - } - /** * Determine if any rows exist for the current query. * diff --git a/README.md b/README.md index 5009fc098..ce8901ad1 100755 --- a/README.md +++ b/README.md @@ -27,9 +27,6 @@ use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; $capsule->setEventDispatcher(new Dispatcher(new Container)); -// Set the cache manager instance used by connections... (optional) -$capsule->setCacheManager(...); - // Make this Capsule instance available globally via static methods... (optional) $capsule->setAsGlobal(); diff --git a/composer.json b/composer.json index dbf91f61c..4ce83c230 100755 --- a/composer.json +++ b/composer.json @@ -18,8 +18,6 @@ "require-dev": { "illuminate/console": "5.0.*", "illuminate/filesystem": "5.0.*", - "illuminate/pagination": "5.0.*", - "illuminate/support": "5.0.*" }, "autoload": { "psr-4": { From 238a427c0e49fe27f087b7f2809a2186d2b03de1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 7 Oct 2014 20:43:42 -0500 Subject: [PATCH 423/577] First pass at simpler Eloquent pagination. --- Eloquent/Builder.php | 21 +++++++++++++++++++++ Eloquent/Model.php | 28 ++++++++++++++++++++++++++++ Query/Builder.php | 19 +++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 28324d6ba..6c665b598 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -1,6 +1,7 @@ model->getPerPage(); + + $page = $page ?: Paginator::resolveCurrentPage(); + + $this->skip(($page - 1) * $perPage)->take($perPage + 1); + + return new Paginator($this->get($columns)->all(), $page, $perPage, [ + 'path' => Paginator::resolveCurrentPath() + ]); + } + /** * Update a record in the database. * diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 845d9e1cc..fc16e704e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -47,6 +47,13 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ protected $primaryKey = 'id'; + /** + * The number of models to return for pagination. + * + * @var int + */ + protected $perPage = 15; + /** * Indicates if the IDs are auto-incrementing. * @@ -2010,6 +2017,27 @@ public function getMorphClass() return $this->morphClass ?: get_class($this); } + /** + * Get the number of models to return per page. + * + * @return int + */ + public function getPerPage() + { + return $this->perPage; + } + + /** + * Set the number of models to return per page. + * + * @param int $perPage + * @return void + */ + public function setPerPage($perPage) + { + $this->perPage = $perPage; + } + /** * Get the default foreign key name for the model. * diff --git a/Query/Builder.php b/Query/Builder.php index 5abb5b953..57b815cb4 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -2,6 +2,7 @@ use Closure; use Illuminate\Support\Collection; +use Illuminate\Pagination\Paginator; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\Query\Grammars\Grammar; use Illuminate\Database\Query\Processors\Processor; @@ -1303,6 +1304,24 @@ public function getFresh($columns = array('*')) return $this->processor->processSelect($this, $this->runSelect()); } + /** + * Paginate the given query into a simple paginator. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function paginate($perPage = 15, $columns = ['*']) + { + $page = $page ?: Paginator::resolveCurrentPage(); + + $this->skip(($page - 1) * $perPage)->take($perPage + 1); + + return new Paginator($this->get($columns), $page, $perPage, [ + 'path' => Paginator::resolveCurrentPath() + ]); + } + /** * Run the query as a "select" statement against the connection. * From 334cb74c46bfdc8fb41d0eca7e7cf7ab37d9034f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Escobar?= Date: Wed, 8 Oct 2014 03:25:54 -0300 Subject: [PATCH 424/577] Push visible and hidden attributes to model --- Eloquent/Model.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index fc16e704e..ac4dce5cf 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2068,6 +2068,19 @@ public function setHidden(array $hidden) { $this->hidden = $hidden; } + + /** + * Add hidden attributes for the model. + * + * @param array|string|null $attributes + * @return void + */ + public function addHidden($attributes = null) + { + if ( ! is_array($attributes)) $attributes = func_get_args(); + + $this->hidden = array_merge($this->hidden, $attributes); + } /** * Set the visible attributes for the model. @@ -2079,6 +2092,19 @@ public function setVisible(array $visible) { $this->visible = $visible; } + + /** + * Add visible attributes for the model. + * + * @param array|string|null $attributes + * @return void + */ + public function addVisible($attributes = null) + { + if ( ! is_array($attributes)) $attributes = func_get_args(); + + $this->visible = array_merge($this->visible, $attributes); + } /** * Set the accessors to append to model arrays. From f89b8e6764c1a9466acf99291cfbabf9980af98e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Oct 2014 08:13:34 -0500 Subject: [PATCH 425/577] Fixing a few bugs. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 57b815cb4..793991d1a 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1313,7 +1313,7 @@ public function getFresh($columns = array('*')) */ public function paginate($perPage = 15, $columns = ['*']) { - $page = $page ?: Paginator::resolveCurrentPage(); + $page = Paginator::resolveCurrentPage(); $this->skip(($page - 1) * $perPage)->take($perPage + 1); From 3ae3293975ac2d69644e7723ea2744db3efcd0a2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Oct 2014 08:43:54 -0500 Subject: [PATCH 426/577] Fixing a few more issues. --- Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 6c665b598..f7cf594dd 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -235,9 +235,9 @@ public function lists($column, $key = null) */ public function paginate($perPage = null, $columns = ['*']) { - $perPage = $perPage ?: $this->model->getPerPage(); + $page = Paginator::resolveCurrentPage(); - $page = $page ?: Paginator::resolveCurrentPage(); + $perPage = $perPage ?: $this->model->getPerPage(); $this->skip(($page - 1) * $perPage)->take($perPage + 1); From 2d52bfe6bde475aaf060ebac490f57ec9ed1894e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Oct 2014 08:47:58 -0500 Subject: [PATCH 427/577] Cleaning up more things. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index f7cf594dd..f691e3709 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -241,7 +241,7 @@ public function paginate($perPage = null, $columns = ['*']) $this->skip(($page - 1) * $perPage)->take($perPage + 1); - return new Paginator($this->get($columns)->all(), $page, $perPage, [ + return new Paginator($this->get($columns)->all(), $perPage, $page, [ 'path' => Paginator::resolveCurrentPath() ]); } From 8c873408b4256e37ed673c98db6faa9612d76f5f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 9 Oct 2014 09:20:11 -0500 Subject: [PATCH 428/577] Working on middleware annotations. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4ce83c230..d3f293f6c 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "illuminate/console": "5.0.*", - "illuminate/filesystem": "5.0.*", + "illuminate/filesystem": "5.0.*" }, "autoload": { "psr-4": { From 03a21aa4b262e342c0b64d2cae70816f1985efe3 Mon Sep 17 00:00:00 2001 From: Abu Bakar Al-Idrus Date: Wed, 15 Oct 2014 19:06:03 +0800 Subject: [PATCH 429/577] * Added new "json" type column into Blueprint.php and corresponding grammars: - Column definition for type "json" in PostgresGrammar.php as "json". - Column definition for type "json" in SqlServerGrammar.php as "nvarchar(max)". - Column definition for "json" type in MySqlGrammar.php as "text". - Column definition for "json" type in SQLiteGrammar.php as "text". --- Schema/Blueprint.php | 12 ++++++++++++ Schema/Grammars/MySqlGrammar.php | 11 +++++++++++ Schema/Grammars/PostgresGrammar.php | 11 +++++++++++ Schema/Grammars/SQLiteGrammar.php | 11 +++++++++++ Schema/Grammars/SqlServerGrammar.php | 11 +++++++++++ 5 files changed, 56 insertions(+) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index ac9712752..64fc6cf37 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -573,6 +573,18 @@ public function enum($column, array $allowed) return $this->addColumn('enum', $column, compact('allowed')); } + /** + * Create a new json column on the table. + * + * @param string $column + * @param array $allowed + * @return \Illuminate\Support\Fluent + */ + public function json($column, array $allowed) + { + return $this->addColumn('json', $column); + } + /** * Create a new date column on the table. * diff --git a/Schema/Grammars/MySqlGrammar.php b/Schema/Grammars/MySqlGrammar.php index 6e518d7fd..9f8c3057f 100755 --- a/Schema/Grammars/MySqlGrammar.php +++ b/Schema/Grammars/MySqlGrammar.php @@ -438,6 +438,17 @@ protected function typeEnum(Fluent $column) return "enum('".implode("', '", $column->allowed)."')"; } + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'text'; + } + /** * Create the column definition for a date type. * diff --git a/Schema/Grammars/PostgresGrammar.php b/Schema/Grammars/PostgresGrammar.php index aedfed0f1..de63407ec 100755 --- a/Schema/Grammars/PostgresGrammar.php +++ b/Schema/Grammars/PostgresGrammar.php @@ -389,6 +389,17 @@ protected function typeEnum(Fluent $column) return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed)."))"; } + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return "json"; + } + /** * Create the column definition for a date type. * diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index c0924dea0..f09970fee 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -453,6 +453,17 @@ protected function typeEnum(Fluent $column) return 'varchar'; } + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'text'; + } + /** * Create the column definition for a date type. * diff --git a/Schema/Grammars/SqlServerGrammar.php b/Schema/Grammars/SqlServerGrammar.php index 3e32903cb..89dd14e50 100755 --- a/Schema/Grammars/SqlServerGrammar.php +++ b/Schema/Grammars/SqlServerGrammar.php @@ -383,6 +383,17 @@ protected function typeEnum(Fluent $column) return 'nvarchar(255)'; } + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'nvarchar(max)'; + } + /** * Create the column definition for a date type. * From 520d9e97054214db88ea20502ee774b3dd22421e Mon Sep 17 00:00:00 2001 From: dbwhddn10 Date: Thu, 16 Oct 2014 23:32:18 +0900 Subject: [PATCH 430/577] fix phpdoc block for Eloquent Model find method add null --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d5d575f70..0e15f6ea8 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -633,7 +633,7 @@ public static function all($columns = array('*')) * * @param mixed $id * @param array $columns - * @return \Illuminate\Support\Collection|static + * @return \Illuminate\Support\Collection|static|null */ public static function find($id, $columns = array('*')) { From 55ab812aed6edc3caf4eb227c5435281c80b8692 Mon Sep 17 00:00:00 2001 From: Jon Palmer Date: Sun, 19 Oct 2014 14:37:29 -0400 Subject: [PATCH 431/577] Cache the method name as well as the attribute for getMutators to avoid the cost of all the studly_case calls. --- Eloquent/Model.php | 71 +++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 0e15f6ea8..e9cdfd372 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -234,6 +234,14 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ const UPDATED_AT = 'updated_at'; + + /** + * The name of this class. Cached to avoid calls to the more expensive get_class. + * + * @var string + */ + protected $clazz; + /** * Create a new Eloquent model instance. * @@ -242,6 +250,8 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ public function __construct(array $attributes = array()) { + $this->clazz = get_class($this); + $this->bootIfNotBooted(); $this->syncOriginal(); @@ -256,11 +266,9 @@ public function __construct(array $attributes = array()) */ protected function bootIfNotBooted() { - $class = get_class($this); - - if ( ! isset(static::$booted[$class])) + if ( ! isset(static::$booted[$this->clazz])) { - static::$booted[$class] = true; + static::$booted[$this->clazz] = true; $this->fireModelEvent('booting', false); @@ -290,7 +298,7 @@ protected static function boot() { if (static::$snakeAttributes) $matches[1] = snake_case($matches[1]); - static::$mutatorCache[$class][] = lcfirst($matches[1]); + static::$mutatorCache[$class][lcfirst($matches[1])] = $matches[0]; } } @@ -393,6 +401,8 @@ public static function observe($class) */ public function fill(array $attributes) { + if (empty($attributes)) return $this; + $totallyGuarded = $this->totallyGuarded(); foreach ($this->fillableFromArray($attributes) as $key => $value) @@ -2255,12 +2265,12 @@ public function attributesToArray() // We want to spin through all the mutated attributes for this model and call // the mutator for the attribute. We cache off every mutated attributes so // we don't have to constantly check on attributes that actually change. - foreach ($this->getMutatedAttributes() as $key) + foreach ($this->getMutatedAttributes() as $key => $method) { if ( ! array_key_exists($key, $attributes)) continue; $attributes[$key] = $this->mutateAttributeForArray( - $key, $attributes[$key] + $method, $attributes[$key] ); } @@ -2269,7 +2279,7 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->getArrayableAppends() as $key) { - $attributes[$key] = $this->mutateAttributeForArray($key, null); + $attributes[$key] = $this->mutateAttributeForArray($this->getMutatorMethod($key), null); } return $attributes; @@ -2387,7 +2397,7 @@ public function getAttribute($key) // If the key references an attribute, we can just go ahead and return the // plain attribute value from the model. This allows every attribute to // be dynamically accessed through the _get method without accessors. - if ($inAttributes || $this->hasGetMutator($key)) + if ($inAttributes || $this->getMutatorMethod($key)) { return $this->getAttributeValue($key); } @@ -2424,11 +2434,10 @@ protected function getAttributeValue($key) // If the attribute has a get mutator, we will call that then return what // it returns as the value, which is useful for transforming values on // retrieval from the model to a form that is more useful for usage. - if ($this->hasGetMutator($key)) - { - return $this->mutateAttribute($key, $value); + $getMutator = $this->getMutatorMethod($key); + if ($getMutator) { + return $this->getMutatedAttributeValue($key, $getMutator); } - // If the attribute is listed as a date, we will convert it to a DateTime // instance on retrieval, which makes it quite convenient to work with // date fields without having to create a mutator for each property. @@ -2440,6 +2449,20 @@ protected function getAttributeValue($key) return $value; } + /** + * Get the mutated value of an attribute. + * + * @param string $key + * @param string $mutatorMethod + * @return mixed + */ + protected function getMutatedAttributeValue($key, $mutatorMethod) + { + $value = $this->getAttributeFromArray($key); + + return $this->mutateAttribute($mutatorMethod, $value); + } + /** * Get an attribute from the $attributes array. * @@ -2477,38 +2500,40 @@ protected function getRelationshipFromMethod($key, $camelKey) } /** - * Determine if a get mutator exists for an attribute. + * Get the method name if a get mutator exists for an attribute. * * @param string $key * @return bool */ - public function hasGetMutator($key) + public function getMutatorMethod($key) { - return method_exists($this, 'get'.studly_case($key).'Attribute'); + $mutators = static::$mutatorCache[$this->clazz]; + + return isset($mutators[$key]) ? $mutators[$key] : null; } /** * Get the value of an attribute using its mutator. * - * @param string $key + * @param string $mutatorMethod * @param mixed $value * @return mixed */ - protected function mutateAttribute($key, $value) + protected function mutateAttribute($mutatorMethod, $value) { - return $this->{'get'.studly_case($key).'Attribute'}($value); + return $this->{$mutatorMethod}($value); } /** * Get the value of an attribute using its mutator for array conversion. * - * @param string $key + * @param string $mutatorMethod * @param mixed $value * @return mixed */ - protected function mutateAttributeForArray($key, $value) + protected function mutateAttributeForArray($mutatorMethod, $value) { - $value = $this->mutateAttribute($key, $value); + $value = $this->mutateAttribute($mutatorMethod, $value); return $value instanceof ArrayableInterface ? $value->toArray() : $value; } @@ -3050,7 +3075,7 @@ public function offsetUnset($offset) public function __isset($key) { return ((isset($this->attributes[$key]) || isset($this->relations[$key])) || - ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))); + ($method = $this->getMutatorMethod($key) && ! is_null($this->getMutatedAttributeValue($key, $method)))); } /** From 0ea294eaca2173b3366d5fb39341a4f8f10d4a8b Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Wed, 22 Oct 2014 12:26:58 +0200 Subject: [PATCH 432/577] Improve concaternation --- Schema/Grammars/SQLiteGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index dfda9af4d..559c13bb5 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -61,7 +61,7 @@ public function compileCreate(Blueprint $blueprint, Fluent $command) $sql .= (string) $this->addPrimaryKeys($blueprint); - return $sql .= ')'; + return $sql . ')'; } /** From 8e5a6b961cf1ab2e670057ba33a13f3b0994201f Mon Sep 17 00:00:00 2001 From: dbwhddn10 Date: Thu, 23 Oct 2014 15:18:21 +0900 Subject: [PATCH 433/577] Fix PHPDoc Block For BelongsToMany Relation withPivot Method fix @param array -> @param mixed --- Eloquent/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 8814b028d..58d8be931 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -941,7 +941,7 @@ public function newExistingPivot(array $attributes = array()) /** * Set the columns on the pivot table to retrieve. * - * @param array $columns + * @param mixed $columns * @return $this */ public function withPivot($columns) From 0df33c4faedf5751f497e665e4e58e8f1b719ca3 Mon Sep 17 00:00:00 2001 From: Robin Hallabro Date: Thu, 23 Oct 2014 14:36:42 +0200 Subject: [PATCH 434/577] Fix model typo in Eloquent/Model.php --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 0e15f6ea8..3547461cc 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -336,7 +336,7 @@ public static function hasGlobalScope($scope) } /** - * Get a global scope registered with the modal. + * Get a global scope registered with the model. * * @param \Illuminate\Database\Eloquent\ScopeInterface $scope * @return \Illuminate\Database\Eloquent\ScopeInterface|null From e182af64219e0890684533cea306889a965a8b0d Mon Sep 17 00:00:00 2001 From: Pieter De Moor Date: Thu, 23 Oct 2014 18:53:41 +0200 Subject: [PATCH 435/577] fix relationsToArray The relationsToArray needs to unset it's relation value at the end of every loop. --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 0e15f6ea8..c23dc240f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2343,6 +2343,8 @@ public function relationsToArray() { $attributes[$key] = $relation; } + + unset($relation); } return $attributes; From dd9871ac28322b2fa9d7e1d19884d9ab3872f6a8 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 30 Oct 2014 15:30:47 +0100 Subject: [PATCH 436/577] Remove leftover variable. --- DatabaseManager.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index ddade604e..3b8693b92 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -191,9 +191,6 @@ protected function prepare(Connection $connection) $connection->setEventDispatcher($this->app['events']); } - $app = $this->app; - - // Here we'll set a reconnector callback. This reconnector can be any callable // so we will set a Closure to reconnect from this manager with the name of // the connection, which will allow us to reconnect from the connections. From c74998f9737bb2834c9de1fdd62d5a916827d13b Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 30 Oct 2014 16:50:56 +0100 Subject: [PATCH 437/577] Use Container contract. --- Connectors/ConnectionFactory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index 17df20cf5..fe3fe5d72 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -1,7 +1,7 @@ Date: Thu, 30 Oct 2014 17:01:09 +0100 Subject: [PATCH 438/577] Prettiness. --- Connectors/ConnectionFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index fe3fe5d72..da2d3ff1c 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -1,11 +1,11 @@ Date: Sat, 1 Nov 2014 14:51:06 -0700 Subject: [PATCH 439/577] setting up order, limit, and offset for union queries --- Query/Builder.php | 32 +++++++++++++++++++++++++++++--- Query/Grammars/Grammar.php | 15 +++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index 1cb8c6460..7462a2f57 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -126,6 +126,27 @@ class Builder { */ public $unions; + /** + * The maximum number of union records to return. + * + * @var int + */ + public $unionLimit; + + /** + * The number of union records to skip. + * + * @var int + */ + public $unionOffset; + + /** + * The orderings for the union query. + * + * @var array + */ + public $unionOrders; + /** * Indicates whether row locking is being used. * @@ -1054,9 +1075,10 @@ public function orHavingRaw($sql, array $bindings = array()) */ public function orderBy($column, $direction = 'asc') { + $property = $this->unions ? 'unionOrders' : 'orders'; $direction = strtolower($direction) == 'asc' ? 'asc' : 'desc'; - $this->orders[] = compact('column', 'direction'); + $this->{$property}[] = compact('column', 'direction'); return $this; } @@ -1109,7 +1131,9 @@ public function orderByRaw($sql, $bindings = array()) */ public function offset($value) { - $this->offset = max(0, $value); + $property = $this->unions ? 'unionOffset' : 'offset'; + + $this->$property = max(0, $value); return $this; } @@ -1133,7 +1157,9 @@ public function skip($value) */ public function limit($value) { - if ($value > 0) $this->limit = $value; + $property = $this->unions ? 'unionLimit' : 'limit'; + + if ($value > 0) $this->$property = $value; return $this; } diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index da8bcc967..1223a2d13 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -555,6 +555,21 @@ protected function compileUnions(Builder $query) $sql .= $this->compileUnion($union); } + if (isset($query->unionOrders)) + { + $sql .= ' '.$this->compileOrders($query, $query->unionOrders); + } + + if (isset($query->unionLimit)) + { + $sql .= ' '.$this->compileLimit($query, $query->unionLimit); + } + + if (isset($query->unionOffset)) + { + $sql .= ' '.$this->compileOffset($query, $query->unionOffset); + } + return ltrim($sql); } From 844fb047d35b647d6b5f3faceb86adda968d6864 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 2 Nov 2014 13:58:00 +0100 Subject: [PATCH 440/577] Add required description to all composer.json files --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index d3f293f6c..bd6238229 100755 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "illuminate/database", + "description": "The Illuminate Database package.", "license": "MIT", "keywords": ["laravel", "database", "sql", "orm"], "authors": [ From fcf1578b08aa338fec85957482fea371638d6242 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 4 Nov 2014 00:30:18 +0100 Subject: [PATCH 441/577] Replace bindShared() with singleton(). --- DatabaseServiceProvider.php | 6 +++--- MigrationServiceProvider.php | 20 ++++++++++---------- SeedServiceProvider.php | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DatabaseServiceProvider.php b/DatabaseServiceProvider.php index f6a127393..a4b6eee22 100755 --- a/DatabaseServiceProvider.php +++ b/DatabaseServiceProvider.php @@ -30,7 +30,7 @@ public function register() // The connection factory is used to create the actual connection instances on // the database. We will inject the factory into the manager so that it may // make the connections while they are actually needed and not of before. - $this->app->bindShared('db.factory', function($app) + $this->app->singleton('db.factory', function($app) { return new ConnectionFactory($app); }); @@ -38,7 +38,7 @@ public function register() // The database manager is used to resolve various connections, since multiple // connections might be managed. It also implements the connection resolver // interface which may be used by other components requiring connections. - $this->app->bindShared('db', function($app) + $this->app->singleton('db', function($app) { return new DatabaseManager($app, $app['db.factory']); }); @@ -51,7 +51,7 @@ public function register() */ protected function registerQueueableEntityResolver() { - $this->app->bindShared('Illuminate\Contracts\Queue\EntityResolver', function() + $this->app->singleton('Illuminate\Contracts\Queue\EntityResolver', function() { return new Eloquent\QueueEntityResolver; }); diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 4328fa0f0..962452dd0 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -45,7 +45,7 @@ public function register() */ protected function registerRepository() { - $this->app->bindShared('migration.repository', function($app) + $this->app->singleton('migration.repository', function($app) { $table = $app['config']['database.migrations']; @@ -63,7 +63,7 @@ protected function registerMigrator() // The migrator is responsible for actually running and rollback the migration // files in the application. We'll pass in our database connection resolver // so the migrator can resolve any of these connections when it needs to. - $this->app->bindShared('migrator', function($app) + $this->app->singleton('migrator', function($app) { $repository = $app['migration.repository']; @@ -106,7 +106,7 @@ protected function registerCommands() */ protected function registerMigrateCommand() { - $this->app->bindShared('command.migrate', function($app) + $this->app->singleton('command.migrate', function($app) { $packagePath = $app['path.base'].'/vendor'; @@ -121,7 +121,7 @@ protected function registerMigrateCommand() */ protected function registerRollbackCommand() { - $this->app->bindShared('command.migrate.rollback', function($app) + $this->app->singleton('command.migrate.rollback', function($app) { return new RollbackCommand($app['migrator']); }); @@ -134,7 +134,7 @@ protected function registerRollbackCommand() */ protected function registerResetCommand() { - $this->app->bindShared('command.migrate.reset', function($app) + $this->app->singleton('command.migrate.reset', function($app) { return new ResetCommand($app['migrator']); }); @@ -147,7 +147,7 @@ protected function registerResetCommand() */ protected function registerRefreshCommand() { - $this->app->bindShared('command.migrate.refresh', function() + $this->app->singleton('command.migrate.refresh', function() { return new RefreshCommand; }); @@ -155,7 +155,7 @@ protected function registerRefreshCommand() protected function registerStatusCommand() { - $this->app->bindShared('command.migrate.status', function($app) + $this->app->singleton('command.migrate.status', function($app) { return new StatusCommand($app['migrator']); }); @@ -168,7 +168,7 @@ protected function registerStatusCommand() */ protected function registerInstallCommand() { - $this->app->bindShared('command.migrate.install', function($app) + $this->app->singleton('command.migrate.install', function($app) { return new InstallCommand($app['migration.repository']); }); @@ -183,7 +183,7 @@ protected function registerMakeCommand() { $this->registerCreator(); - $this->app->bindShared('command.migrate.make', function($app) + $this->app->singleton('command.migrate.make', function($app) { // Once we have the migration creator registered, we will create the command // and inject the creator. The creator is responsible for the actual file @@ -203,7 +203,7 @@ protected function registerMakeCommand() */ protected function registerCreator() { - $this->app->bindShared('migration.creator', function($app) + $this->app->singleton('migration.creator', function($app) { return new MigrationCreator($app['files']); }); diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index 7b5e6d44c..3dd93c177 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -21,7 +21,7 @@ public function register() { $this->registerSeedCommand(); - $this->app->bindShared('seeder', function() + $this->app->singleton('seeder', function() { return new Seeder; }); @@ -36,7 +36,7 @@ public function register() */ protected function registerSeedCommand() { - $this->app->bindShared('command.seed', function($app) + $this->app->singleton('command.seed', function($app) { return new SeedCommand($app['db']); }); From 2bac008c712dacc6018d6fd5bca416bdda760910 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 6 Nov 2014 11:03:47 +0100 Subject: [PATCH 442/577] Also remove else with throw --- Eloquent/QueueEntityResolver.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Eloquent/QueueEntityResolver.php b/Eloquent/QueueEntityResolver.php index 8a784fb64..2dc2be52c 100644 --- a/Eloquent/QueueEntityResolver.php +++ b/Eloquent/QueueEntityResolver.php @@ -20,10 +20,8 @@ public function resolve($type, $id) { return $instance; } - else - { - throw new EntityNotFoundException($type, $id); - } + + throw new EntityNotFoundException($type, $id); } } From 04c290d77ff7a7413152b2c28c4f61fbb2e6e786 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 7 Nov 2014 09:38:46 -0600 Subject: [PATCH 443/577] Rename some traits to be less stupid. --- Eloquent/{SoftDeletingTrait.php => SoftDeletes.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Eloquent/{SoftDeletingTrait.php => SoftDeletes.php} (97%) diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletes.php similarity index 97% rename from Eloquent/SoftDeletingTrait.php rename to Eloquent/SoftDeletes.php index e54523bd2..90706b1e4 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletes.php @@ -1,6 +1,6 @@ Date: Mon, 10 Nov 2014 19:56:18 +0100 Subject: [PATCH 444/577] general code cleanup --- DatabaseManager.php | 2 +- Eloquent/Relations/MorphPivot.php | 1 - SeedServiceProvider.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 3b8693b92..85517e21b 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -303,4 +303,4 @@ public function __call($method, $parameters) return call_user_func_array(array($this->connection(), $method), $parameters); } -} +} diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index 1f0d252a0..fe8c644b2 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -75,5 +75,4 @@ public function setMorphClass($morphClass) return $this; } - } diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index 3dd93c177..bf2c8144c 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -52,4 +52,4 @@ public function provides() return array('seeder', 'command.seed'); } -} +} From 5271dbc7097a69395c718132940a77a16f00a00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Escobar?= Date: Wed, 12 Nov 2014 00:19:37 -0300 Subject: [PATCH 445/577] Add getVisible method --- Eloquent/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ac4dce5cf..667652912 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2081,6 +2081,16 @@ public function addHidden($attributes = null) $this->hidden = array_merge($this->hidden, $attributes); } + + /** + * Get the visible attributes for the model. + * + * @return array + */ + public function getVisible() + { + return $this->visible; + } /** * Set the visible attributes for the model. From 01dd109bc1eda2ee734dc1e55530e3dba65418b0 Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Thu, 13 Nov 2014 11:44:30 -0800 Subject: [PATCH 446/577] Fix broken support for PDO::FETCH_ASSOC in Schema::hasColumn() --- Query/Processors/MySqlProcessor.php | 2 +- Query/Processors/PostgresProcessor.php | 2 +- Query/Processors/SQLiteProcessor.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Query/Processors/MySqlProcessor.php b/Query/Processors/MySqlProcessor.php index dd2f4d892..f77b41db2 100644 --- a/Query/Processors/MySqlProcessor.php +++ b/Query/Processors/MySqlProcessor.php @@ -10,7 +10,7 @@ class MySqlProcessor extends Processor { */ public function processColumnListing($results) { - return array_map(function($r) { return $r->column_name; }, $results); + return array_map(function($r) { $r = (object) $r; return $r->column_name; }, $results); } } diff --git a/Query/Processors/PostgresProcessor.php b/Query/Processors/PostgresProcessor.php index c46f29846..665379df4 100755 --- a/Query/Processors/PostgresProcessor.php +++ b/Query/Processors/PostgresProcessor.php @@ -34,7 +34,7 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu */ public function processColumnListing($results) { - return array_values(array_map(function($r) { return $r->column_name; }, $results)); + return array_values(array_map(function($r) { $r = (object) $r; return $r->column_name; }, $results)); } } diff --git a/Query/Processors/SQLiteProcessor.php b/Query/Processors/SQLiteProcessor.php index dbd3e7e39..34493bf6e 100644 --- a/Query/Processors/SQLiteProcessor.php +++ b/Query/Processors/SQLiteProcessor.php @@ -10,7 +10,7 @@ class SQLiteProcessor extends Processor { */ public function processColumnListing($results) { - return array_values(array_map(function($r) { return $r->name; }, $results)); + return array_values(array_map(function($r) { $r = (object) $r; return $r->name; }, $results)); } } From 60cab205a7abde16b05a1b5e3988301537767781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Escobar?= Date: Thu, 13 Nov 2014 20:17:26 -0300 Subject: [PATCH 447/577] Update attributes line for readability --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 667652912..64fa21f34 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2077,7 +2077,7 @@ public function setHidden(array $hidden) */ public function addHidden($attributes = null) { - if ( ! is_array($attributes)) $attributes = func_get_args(); + $attributes = is_array($attributes) ? $attributes : func_get_args(); $this->hidden = array_merge($this->hidden, $attributes); } @@ -2111,7 +2111,7 @@ public function setVisible(array $visible) */ public function addVisible($attributes = null) { - if ( ! is_array($attributes)) $attributes = func_get_args(); + $attributes = is_array($attributes) ? $attributes : func_get_args(); $this->visible = array_merge($this->visible, $attributes); } From c71610a365866e5ecc9a2164d0c92195bf4214d1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 19 Nov 2014 22:26:06 -0600 Subject: [PATCH 448/577] remove spaces. --- Schema/Grammars/SQLiteGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/SQLiteGrammar.php b/Schema/Grammars/SQLiteGrammar.php index d2e588a3a..535684b34 100755 --- a/Schema/Grammars/SQLiteGrammar.php +++ b/Schema/Grammars/SQLiteGrammar.php @@ -61,7 +61,7 @@ public function compileCreate(Blueprint $blueprint, Fluent $command) $sql .= (string) $this->addPrimaryKeys($blueprint); - return $sql . ')'; + return $sql.')'; } /** From 97774554f6e1d57e7eb002e006e7acd8f589989c Mon Sep 17 00:00:00 2001 From: Sasha Joseph Date: Thu, 20 Nov 2014 17:11:15 -0500 Subject: [PATCH 449/577] Fixes join bindings bug when query is invoked multiple times --- Query/Grammars/Grammar.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index da8bcc967..1c0c8a591 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -142,8 +142,9 @@ protected function compileJoins(Builder $query, $joins) $clauses[] = $this->compileJoinConstraint($clause); } - foreach ($join->bindings as $binding) + foreach ($join->bindings as $index => $binding) { + unset($join->bindings[$index]); $query->addBinding($binding, 'join'); } From 5d32472ecd86237c96d5e563accf0c5fb2d1cef5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 21 Nov 2014 12:43:42 -0600 Subject: [PATCH 450/577] Line space. --- Query/Grammars/Grammar.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 1c0c8a591..759405994 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -145,6 +145,7 @@ protected function compileJoins(Builder $query, $joins) foreach ($join->bindings as $index => $binding) { unset($join->bindings[$index]); + $query->addBinding($binding, 'join'); } From 2ab3e0df1354d7cf4089466d5320fc49f5517184 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 24 Nov 2014 10:11:07 -0600 Subject: [PATCH 451/577] Added forceFill and forceCreate methods. --- Eloquent/Model.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 6c1f79dd1..6694e43ac 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -417,6 +417,23 @@ public function fill(array $attributes) return $this; } + /** + * Fill the model with an array of attributes. Force mass assignment. + * + * @param array $attributes + * @return $this + */ + public function forceFill(array $attributes) + { + static::unguard(); + + $this->fill($attributes); + + static::reguard(); + + return $this; + } + /** * Get the fillable attributes of a given array. * @@ -530,6 +547,23 @@ public static function create(array $attributes) return $model; } + /** + * Save a new model and return the instance. Allow mass-assignment. + * + * @param array $attributes + * @return static + */ + public static function forceCreate(array $attributes) + { + static::unguard(); + + $model = static::create($attributes); + + static::reguard(); + + return $model; + } + /** * Get the first record matching the attributes or create it. * From 2675f6dc9263d48fa1e71518fcb1b587f3229139 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Nov 2014 11:55:45 -0600 Subject: [PATCH 452/577] Make length aware pagination the default like L4. --- Eloquent/Builder.php | 24 +++++++++++++- Query/Builder.php | 78 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index f691e3709..c2c042206 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -3,6 +3,7 @@ use Closure; use Illuminate\Pagination\Paginator; use Illuminate\Database\Query\Expression; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\Builder as QueryBuilder; @@ -226,6 +227,27 @@ public function lists($column, $key = null) return $results; } + /** + * Paginate the given query. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function paginate($perPage = 15, $columns = ['*']) + { + $total = $this->query->getCountForPagination(); + + $this->query->forPage( + $page = Paginator::resolveCurrentPage(), + $perPage = $perPage ?: $this->model->getPerPage() + ); + + return new LengthAwarePaginator($this->get($columns)->all(), $total, $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath() + ]); + } + /** * Paginate the given query into a simple paginator. * @@ -233,7 +255,7 @@ public function lists($column, $key = null) * @param array $columns * @return \Illuminate\Contracts\Pagination\Paginator */ - public function paginate($perPage = null, $columns = ['*']) + public function simplePaginate($perPage = null, $columns = ['*']) { $page = Paginator::resolveCurrentPage(); diff --git a/Query/Builder.php b/Query/Builder.php index 872428030..cafa6eb95 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -5,6 +5,7 @@ use Illuminate\Pagination\Paginator; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\Query\Grammars\Grammar; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Database\Query\Processors\Processor; class Builder { @@ -134,6 +135,13 @@ class Builder { */ public $lock; + /** + * The field backups currently in use. + * + * @var array + */ + protected $backups = []; + /** * All of the available clause operators. * @@ -1310,12 +1318,34 @@ public function getFresh($columns = array('*')) * * @param int $perPage * @param array $columns - * @return \Illuminate\Contracts\Pagination\Paginator + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ public function paginate($perPage = 15, $columns = ['*']) { $page = Paginator::resolveCurrentPage(); + $total = $this->getCountForPagination(); + + $results = $this->forPage($page, $perPage)->get($columns); + + return new LengthAwarePaginator($results, $total, $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath() + ]); + } + + /** + * Get a paginator only supporting simple next and previous links. + * + * This is more efficient on larger data-sets, etc. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function simplePaginate($perPage = 15, $columns = ['*']) + { + $page = Paginator::resolveCurrentPage(); + $this->skip(($page - 1) * $perPage)->take($perPage + 1); return new Paginator($this->get($columns), $page, $perPage, [ @@ -1323,6 +1353,52 @@ public function paginate($perPage = 15, $columns = ['*']) ]); } + /** + * Get the count of the total records for the paginator. + * + * @return in + */ + public function getCountForPagination() + { + $this->backupFieldsForCount(); + + $total = $this->count(); + + $this->restoreFieldsForCount(); + + return $total; + } + + /** + * Backup some fields for the pagination count. + * + * @return void + */ + protected function backupFieldsForCount() + { + foreach (['orders', 'limit', 'offset'] as $field) + { + $this->backups[$field] = $this->{$field}; + + $this->{$field} = null; + } + } + + /** + * Restore some fields after the pagination count. + * + * @return void + */ + protected function restoreFieldsForCount() + { + foreach (['orders', 'limit', 'offset'] as $field) + { + $this->{$field} = $this->backups[$field]; + } + + $this->backups = []; + } + /** * Run the query as a "select" statement against the connection. * From 07bf17056f3498cefb25f70af478df0e2a1a266f Mon Sep 17 00:00:00 2001 From: jongwoo Yoo Date: Thu, 27 Nov 2014 14:44:45 +0900 Subject: [PATCH 453/577] morphClass property not applied bug when select morphToMany Relation --- Eloquent/Relations/MorphToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index b376aa53f..2d8d6ac9d 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -45,7 +45,7 @@ public function __construct(Builder $query, Model $parent, $name, $table, $forei { $this->inverse = $inverse; $this->morphType = $name.'_type'; - $this->morphClass = $inverse ? get_class($query->getModel()) : get_class($parent); + $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName); } From 08970b80ab3144d82b84662b3f4c672d3e67a816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0rfan=20Evrens?= Date: Fri, 28 Nov 2014 18:14:52 +0200 Subject: [PATCH 454/577] exists function improved adding a limit(1) is usefull for control of existence and can be find it 1 step in db. --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index 1cb8c6460..c19a86617 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1690,7 +1690,7 @@ protected function restoreFieldsForCount() */ public function exists() { - return $this->count() > 0; + return $this->limit(1)->count() > 0; } /** From e067562e295aea78e1b11952d0668b61f2863767 Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Fri, 28 Nov 2014 16:32:31 -0500 Subject: [PATCH 455/577] Spelling: built -> build --- Schema/Blueprint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index cb3de29ad..832b487af 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -696,7 +696,7 @@ protected function dropIndexCommand($command, $type, $index) // If the given "index" is actually an array of columns, the developer means // to drop an index merely by specifying the columns involved without the - // conventional name, so we will built the index name from the columns. + // conventional name, so we will build the index name from the columns. if (is_array($index)) { $columns = $index; From 42d237fbb1663412e9c2668e5e4a67d340adea11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0rfan=20Evrens?= Date: Tue, 2 Dec 2014 02:20:20 +0200 Subject: [PATCH 456/577] a tiny change --- Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index cafa6eb95..380022753 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1356,7 +1356,7 @@ public function simplePaginate($perPage = 15, $columns = ['*']) /** * Get the count of the total records for the paginator. * - * @return in + * @return int */ public function getCountForPagination() { From a29cc568752d1e3dec4160cc50153246bff827ff Mon Sep 17 00:00:00 2001 From: Bryce Ray Date: Tue, 2 Dec 2014 14:29:01 -0600 Subject: [PATCH 457/577] Fixing issue with global scope duplication in relationship has requests --- Eloquent/Builder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 2cea79d7c..abf3ad3ef 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -683,6 +683,11 @@ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) // the has query, and then copy the bindings from the "has" query to the main. $relationQuery = $relation->getBaseQuery(); + // The relation query is going to have all the necessary global scope definitions + // If the global scopes aren't removed here then they will be duplicated in the final + // Query. This is noticeable when a global scope includes where clauses. + $hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery); + $hasQuery->mergeWheres( $relationQuery->wheres, $relationQuery->getBindings() ); From b4b16f6c07578826b169b4831e4bf0703b42d785 Mon Sep 17 00:00:00 2001 From: Bryce Ray Date: Tue, 2 Dec 2014 15:04:13 -0600 Subject: [PATCH 458/577] Fixing formattting to use tabs --- Eloquent/Builder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index abf3ad3ef..943301a0f 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -672,8 +672,8 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, /** * Merge the "wheres" from a relation query to a has query. * - * @param \Illuminate\Database\Eloquent\Builder $hasQuery - * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @param \Illuminate\Database\Eloquent\Builder $hasQuery + * @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @return void */ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) @@ -683,10 +683,10 @@ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) // the has query, and then copy the bindings from the "has" query to the main. $relationQuery = $relation->getBaseQuery(); - // The relation query is going to have all the necessary global scope definitions - // If the global scopes aren't removed here then they will be duplicated in the final - // Query. This is noticeable when a global scope includes where clauses. - $hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery); + // The relation query is going to have all the necessary global scope definitions + // If the global scopes aren't removed here then they will be duplicated in the final + // Query. This is noticeable when a global scope includes where clauses. + $hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery); $hasQuery->mergeWheres( $relationQuery->wheres, $relationQuery->getBindings() From c25b6d5f61daa39e22fcdd8b1c0f433fd84819ee Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Tue, 2 Dec 2014 18:18:36 -0500 Subject: [PATCH 459/577] Add $key $value support to contains and where methods --- Eloquent/Collection.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Eloquent/Collection.php b/Eloquent/Collection.php index dc520e56d..ae661431d 100755 --- a/Eloquent/Collection.php +++ b/Eloquent/Collection.php @@ -62,11 +62,17 @@ public function add($item) * Determine if a key exists in the collection. * * @param mixed $key + * @param mixed $value * @return bool */ - public function contains($key) + public function contains($key, $value = null) { - return ! is_null($this->find($key)); + if (func_num_args() == 1) + { + return ! is_null($this->find($key)); + } + + return parent::contains($key, $value); } /** From c45bb0aad220df9a057bc5a1674ea0cc99a2f8f1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Dec 2014 20:35:27 -0600 Subject: [PATCH 460/577] Continue to tweak things for workbench changes. --- Console/Migrations/BaseCommand.php | 32 ----------------------- Console/Migrations/MigrateCommand.php | 4 --- Console/Migrations/MigrateMakeCommand.php | 4 --- 3 files changed, 40 deletions(-) diff --git a/Console/Migrations/BaseCommand.php b/Console/Migrations/BaseCommand.php index 7c0d31187..f24024bb9 100755 --- a/Console/Migrations/BaseCommand.php +++ b/Console/Migrations/BaseCommand.php @@ -11,38 +11,6 @@ class BaseCommand extends Command { */ protected function getMigrationPath() { - $path = $this->input->getOption('path'); - - // First, we will check to see if a path option has been defined. If it has - // we will use the path relative to the root of this installation folder - // so that migrations may be run for any path within the applications. - if ( ! is_null($path)) - { - return $this->laravel['path.base'].'/'.$path; - } - - $package = $this->input->getOption('package'); - - // If the package is in the list of migration paths we received we will put - // the migrations in that path. Otherwise, we will assume the package is - // is in the package directories and will place them in that location. - if ( ! is_null($package)) - { - return $this->packagePath.'/'.$package.'/src/migrations'; - } - - $bench = $this->input->getOption('bench'); - - // Finally we will check for the workbench option, which is a shortcut into - // specifying the full path for a "workbench" project. Workbenches allow - // developers to develop packages along side a "standard" app install. - if ( ! is_null($bench)) - { - $path = "/workbench/{$bench}/src/migrations"; - - return $this->laravel['path.base'].$path; - } - return $this->laravel['path.database'].'/migrations'; } diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 035192fd8..8c5c779ca 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -111,16 +111,12 @@ protected function prepareDatabase() protected function getOptions() { return array( - array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null), - array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null), - array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null), - array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), diff --git a/Console/Migrations/MigrateMakeCommand.php b/Console/Migrations/MigrateMakeCommand.php index 68c4be463..e2f3d1a6e 100644 --- a/Console/Migrations/MigrateMakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -112,12 +112,8 @@ protected function getArguments() protected function getOptions() { return array( - array('bench', null, InputOption::VALUE_OPTIONAL, 'The workbench the migration belongs to.', null), - array('create', null, InputOption::VALUE_OPTIONAL, 'The table to be created.'), - array('package', null, InputOption::VALUE_OPTIONAL, 'The package the migration belongs to.', null), - array('path', null, InputOption::VALUE_OPTIONAL, 'Where to store the migration.', null), array('table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'), From 7078b9c4c532b09180f02f7b51e6858ba87950c4 Mon Sep 17 00:00:00 2001 From: Jason Walton Date: Sun, 7 Dec 2014 19:52:19 -0700 Subject: [PATCH 461/577] Fix composer dump-autoload command after make:migration --- Console/Migrations/MigrateMakeCommand.php | 12 ++++++++++-- MigrationServiceProvider.php | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Console/Migrations/MigrateMakeCommand.php b/Console/Migrations/MigrateMakeCommand.php index e2f3d1a6e..58f4d7d5b 100644 --- a/Console/Migrations/MigrateMakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -1,5 +1,6 @@ creator = $creator; + $this->composer = $composer; $this->packagePath = $packagePath; } @@ -72,7 +80,7 @@ public function fire() // make sure that the migrations are registered by the class loaders. $this->writeMigration($name, $table, $create); - $this->call('dump-autoload'); + $this->composer->dumpAutoloads(); } /** diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 962452dd0..247501797 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -192,7 +192,9 @@ protected function registerMakeCommand() $packagePath = $app['path.base'].'/vendor'; - return new MigrateMakeCommand($creator, $packagePath); + $composer = $app['composer']; + + return new MigrateMakeCommand($creator, $composer, $packagePath); }); } From c2daf9f33376129d0d405d99d5b0d753f5dcc5d4 Mon Sep 17 00:00:00 2001 From: Jalen Lyu Date: Tue, 9 Dec 2014 00:37:17 +0800 Subject: [PATCH 462/577] add useWritePdo for select query --- Query/Builder.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Query/Builder.php b/Query/Builder.php index 1cb8c6460..ad09dc956 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -180,6 +180,13 @@ class Builder { 'rlike', 'regexp', 'not regexp', ); + /** + * Whether use write pdo for select. + * + * @var bool + */ + protected $useWritePdo = false; + /** * Create a new query builder instance. * @@ -1356,6 +1363,10 @@ public function getFresh($columns = array('*')) */ protected function runSelect() { + if ($this->useWritePdo) { + return $this->connection->select($this->toSql(), $this->getBindings(), false); + } + return $this->connection->select($this->toSql(), $this->getBindings()); } @@ -2092,6 +2103,13 @@ public function getGrammar() return $this->grammar; } + public function useWritePdo() + { + $this->useWritePdo = true; + + return $this; + } + /** * Handle dynamic method calls into the method. * From 2ce3276d6ce1e958851ba804b0ad6a9054f38848 Mon Sep 17 00:00:00 2001 From: Jalen Lyu Date: Fri, 12 Dec 2014 00:55:25 +0800 Subject: [PATCH 463/577] add onWrite method to let Model use write pdo for selecting --- Eloquent/Model.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e4918d907..9d3d9a223 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -644,6 +644,13 @@ public static function find($id, $columns = array('*')) return $instance->newQuery()->find($id, $columns); } + public static function onWrite() + { + $instance = new static; + + return $instance->newQuery()->useWritePdo(); + } + /** * Find a model by its primary key or return new static. * From 5abc60070d5046e962f710bfa88da373a0bcefe5 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Oct 2014 19:40:58 +0200 Subject: [PATCH 464/577] Set $options as an empty array per default --- Eloquent/Model.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e4918d907..4130346d0 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1467,9 +1467,10 @@ protected function finishSave(array $options) * Perform a model update operation. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $options * @return bool|null */ - protected function performUpdate(Builder $query, array $options) + protected function performUpdate(Builder $query, array $options = []) { $dirty = $this->getDirty(); @@ -1511,9 +1512,10 @@ protected function performUpdate(Builder $query, array $options) * Perform a model insert operation. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $options * @return bool */ - protected function performInsert(Builder $query, array $options) + protected function performInsert(Builder $query, array $options = []) { if ($this->fireModelEvent('creating') === false) return false; From b0a70e0e67165303e0a0b737643df71180d3946e Mon Sep 17 00:00:00 2001 From: Derek Myers Date: Thu, 11 Dec 2014 14:04:13 -0600 Subject: [PATCH 465/577] Fixed port separator in DSN when using dblib with PDO in sql server connector --- Connectors/SqlServerConnector.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index b6660752f..d1d9a5317 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -42,13 +42,15 @@ protected function getDsn(array $config) // First we will create the basic DSN setup as well as the port if it is in // in the configuration options. This will give us the basic DSN we will // need to establish the PDO connections and return them back for use. - $port = isset($config['port']) ? ','.$port : ''; - if (in_array('dblib', $this->getAvailableDrivers())) { + $port = isset($config['port']) ? ':'.$port : ''; + return "dblib:host={$host}{$port};dbname={$database}"; } + $port = isset($config['port']) ? ','.$port : ''; + $dbName = $database != '' ? ";Database={$database}" : ''; return "sqlsrv:Server={$host}{$port}{$dbName}"; From fcca977d8f69873ae59fca9b6bfebe35681815dc Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 13 Dec 2014 17:20:05 +0000 Subject: [PATCH 466/577] CS fixes Signed-off-by: Graham Campbell --- Connectors/Connector.php | 10 +++++----- Connectors/PostgresConnector.php | 8 ++++---- Connectors/SqlServerConnector.php | 8 ++++---- Eloquent/Model.php | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Connectors/Connector.php b/Connectors/Connector.php index 0c16093b4..6c388e068 100755 --- a/Connectors/Connector.php +++ b/Connectors/Connector.php @@ -10,11 +10,11 @@ class Connector { * @var array */ protected $options = array( - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_EMULATE_PREPARES => false, ); /** diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 39b50e37b..9c330adac 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -10,10 +10,10 @@ class PostgresConnector extends Connector implements ConnectorInterface { * @var array */ protected $options = array( - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, ); /** diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index b6660752f..cdbfb25d9 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -10,10 +10,10 @@ class SqlServerConnector extends Connector implements ConnectorInterface { * @var array */ protected $options = array( - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_CASE => PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, ); /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 25890415f..8cdd1b111 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1055,7 +1055,7 @@ public function morphedByMany($related, $name, $table = null, $foreignKey = null /** * Get the relationship name of the belongs to many. * - * @return string + * @return string */ protected function getBelongsToManyCaller() { From 34e00dca2842a5862d11d4045dbb0e6cd7122c92 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 13 Dec 2014 17:31:00 +0000 Subject: [PATCH 467/577] CS fixes Signed-off-by: Graham Campbell --- DatabaseManager.php | 2 +- SeedServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DatabaseManager.php b/DatabaseManager.php index 85517e21b..3b8693b92 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -303,4 +303,4 @@ public function __call($method, $parameters) return call_user_func_array(array($this->connection(), $method), $parameters); } -} +} diff --git a/SeedServiceProvider.php b/SeedServiceProvider.php index bf2c8144c..3dd93c177 100755 --- a/SeedServiceProvider.php +++ b/SeedServiceProvider.php @@ -52,4 +52,4 @@ public function provides() return array('seeder', 'command.seed'); } -} +} From 9fbcf40225d47e218d2bf99cd04834f75778f972 Mon Sep 17 00:00:00 2001 From: Jalen Lyu Date: Sun, 14 Dec 2014 17:42:40 +0800 Subject: [PATCH 468/577] adjust coding style --- Query/Builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index ad09dc956..f21f4defd 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1363,7 +1363,8 @@ public function getFresh($columns = array('*')) */ protected function runSelect() { - if ($this->useWritePdo) { + if ($this->useWritePdo) + { return $this->connection->select($this->toSql(), $this->getBindings(), false); } From 59048cdac4ff2805361f9431658700c102d5fdde Mon Sep 17 00:00:00 2001 From: Jalen Lyu Date: Mon, 15 Dec 2014 18:49:46 +0800 Subject: [PATCH 469/577] add docblock --- Eloquent/Model.php | 5 +++++ Query/Builder.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 9d3d9a223..14181622f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -644,6 +644,11 @@ public static function find($id, $columns = array('*')) return $instance->newQuery()->find($id, $columns); } + /** + * Begin querying the model on the write connection. + * + * @return \Illuminate\Database\Query\Builder + */ public static function onWrite() { $instance = new static; diff --git a/Query/Builder.php b/Query/Builder.php index f21f4defd..155dabd78 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -2104,6 +2104,11 @@ public function getGrammar() return $this->grammar; } + /** + * Use the write pdo for query. + * + * @return $this + */ public function useWritePdo() { $this->useWritePdo = true; From a0f10150b8bef577dab4532c2d49d811c198d8b3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 15 Dec 2014 13:26:15 -0600 Subject: [PATCH 470/577] Clean up a few things. --- Connectors/SqlServerConnector.php | 38 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/Connectors/SqlServerConnector.php b/Connectors/SqlServerConnector.php index d8ce0402a..c4d14c238 100755 --- a/Connectors/SqlServerConnector.php +++ b/Connectors/SqlServerConnector.php @@ -37,23 +37,45 @@ public function connect(array $config) */ protected function getDsn(array $config) { - extract($config); - // First we will create the basic DSN setup as well as the port if it is in // in the configuration options. This will give us the basic DSN we will // need to establish the PDO connections and return them back for use. if (in_array('dblib', $this->getAvailableDrivers())) { - $port = isset($config['port']) ? ':'.$port : ''; - - return "dblib:host={$host}{$port};dbname={$database}"; + return $this->getDblibDsn($config); } + else + { + return $this->getSqlSrvDsn($config); + } + } + + /** + * Get the DSN string for a DbLib connection. + * + * @param array $config + * @return string + */ + protected function getDblibDsn(array $config) + { + $port = isset($config['port']) ? ':'.$config['port'] : ''; - $port = isset($config['port']) ? ','.$port : ''; + return "dblib:host={$config['host']}{$port};dbname={$config['database']}"; + } + + /** + * Get the DSN string for a SqlSrv connection. + * + * @param array $config + * @return string + */ + protected function getSqlSrvDsn(array $config) + { + $port = isset($config['port']) ? ','.$config['port'] : ''; - $dbName = $database != '' ? ";Database={$database}" : ''; + $dbName = $config['database'] != '' ? ";Database={$config['database']}" : ''; - return "sqlsrv:Server={$host}{$port}{$dbName}"; + return "sqlsrv:Server={$config['host']}{$port}{$dbName}"; } /** From 0a21bf1d5cfaedef4d5ff66edac46bfe2d2b7f30 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 15 Dec 2014 13:28:51 -0600 Subject: [PATCH 471/577] Fix method name. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 14181622f..7c5c19a9e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -649,7 +649,7 @@ public static function find($id, $columns = array('*')) * * @return \Illuminate\Database\Query\Builder */ - public static function onWrite() + public static function onWriteConnection() { $instance = new static; From f0c111ef01d96ef50a0a2b427a75b7c6c32b2b6e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 09:27:43 -0600 Subject: [PATCH 472/577] Remove comment. --- Eloquent/Builder.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 943301a0f..9d017cff5 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -683,9 +683,6 @@ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) // the has query, and then copy the bindings from the "has" query to the main. $relationQuery = $relation->getBaseQuery(); - // The relation query is going to have all the necessary global scope definitions - // If the global scopes aren't removed here then they will be duplicated in the final - // Query. This is noticeable when a global scope includes where clauses. $hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery); $hasQuery->mergeWheres( From a14f08bdbabda8f2ef3f3b2687114b04d8a641ac Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 09:35:50 -0600 Subject: [PATCH 473/577] Fix code to not be a breaking chage. --- Query/Builder.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index dbbd43cdb..889c91e9c 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1702,7 +1702,13 @@ protected function restoreFieldsForCount() */ public function exists() { - return $this->limit(1)->count() > 0; + $limit = $this->limit; + + $result = $this->limit(1)->count() > 0; + + $this->limit($limit); + + return $result; } /** From b084568319c77e406d64ffaa3664e45fd69f895e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 10:56:54 -0600 Subject: [PATCH 474/577] Working on formatting. --- Eloquent/Relations/BelongsToMany.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 90b8aa7b5..4886f707d 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -707,7 +707,8 @@ protected function createAttachRecords($ids, array $attributes) { $records = array(); - $timed = ($this->hasPivotColumn($this->createdAt()) || $this->hasPivotColumn($this->updatedAt())); + $timed = ($this->hasPivotColumn($this->createdAt()) || + $this->hasPivotColumn($this->updatedAt())); // To create the attachment records, we will simply spin through the IDs given // and create a new record to insert for each ID. Each ID may actually be a From 470e9ec2bc8b5bcd6f445f7607777139206a92d5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 14:13:42 -0600 Subject: [PATCH 475/577] Working on code formatting. --- Connection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index 4a9933d04..b8c6e4c4f 100755 --- a/Connection.php +++ b/Connection.php @@ -831,7 +831,8 @@ public function getReadPdo() */ public function setPdo($pdo) { - if ($this->transactions >= 1) throw new \RuntimeException("Attempt to change PDO inside running transaction"); + if ($this->transactions >= 1) + throw new \RuntimeException("Can't swap PDO instance while within transaction."); $this->pdo = $pdo; From 3ef78bc2294a7b7adbca2f6de971da698b8b37ec Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 22:06:05 -0600 Subject: [PATCH 476/577] Make sure we have an array in push method. --- Eloquent/Model.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 005db8049..f2688500e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1470,7 +1470,9 @@ public function push() // us to recurs into all of these nested relations for this model instance. foreach ($this->relations as $models) { - foreach (Collection::make($models) as $model) + $models = is_array($models) ? $models : array($models); + + foreach ($models as $model) { if ( ! $model->push()) return false; } @@ -2116,7 +2118,7 @@ public function setHidden(array $hidden) { $this->hidden = $hidden; } - + /** * Add hidden attributes for the model. * @@ -2126,10 +2128,10 @@ public function setHidden(array $hidden) public function addHidden($attributes = null) { $attributes = is_array($attributes) ? $attributes : func_get_args(); - + $this->hidden = array_merge($this->hidden, $attributes); } - + /** * Get the visible attributes for the model. * @@ -2150,7 +2152,7 @@ public function setVisible(array $visible) { $this->visible = $visible; } - + /** * Add visible attributes for the model. * @@ -2160,7 +2162,7 @@ public function setVisible(array $visible) public function addVisible($attributes = null) { $attributes = is_array($attributes) ? $attributes : func_get_args(); - + $this->visible = array_merge($this->visible, $attributes); } From bb862fdf3546a9cf510fd708dd76f830e2a2b8ca Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 22:44:06 -0600 Subject: [PATCH 477/577] Use freshTimestampString. --- Eloquent/Relations/HasOneOrMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 83bc7eee2..e6c338c75 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -230,7 +230,7 @@ public function update(array $attributes) { if ($this->related->usesTimestamps()) { - $attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestamp(); + $attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestampString(); } return $this->query->update($attributes); From 3ff7249c39fb4ead961f13322fd5f8884ebf46ad Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 16 Dec 2014 22:56:33 -0600 Subject: [PATCH 478/577] cleaning up some code. --- Eloquent/Model.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b36dd8ceb..086e75bac 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -236,11 +236,11 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa /** - * The name of this class. Cached to avoid calls to the more expensive get_class. + * The name of this class. Cached to avoid calls to get_class + studly_case. * * @var string */ - protected $clazz; + protected $klass; /** * Create a new Eloquent model instance. @@ -250,7 +250,7 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ public function __construct(array $attributes = array()) { - $this->clazz = get_class($this); + $this->klass = get_class($this); $this->bootIfNotBooted(); @@ -266,9 +266,9 @@ public function __construct(array $attributes = array()) */ protected function bootIfNotBooted() { - if ( ! isset(static::$booted[$this->clazz])) + if ( ! isset(static::$booted[$this->klass])) { - static::$booted[$this->clazz] = true; + static::$booted[$this->klass] = true; $this->fireModelEvent('booting', false); @@ -2293,7 +2293,9 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->getArrayableAppends() as $key) { - $attributes[$key] = $this->mutateAttributeForArray($this->getMutatorMethod($key), null); + $attributes[$key] = $this->mutateAttributeForArray( + $this->getMutatorMethod($key), null + ); } return $attributes; @@ -2523,7 +2525,7 @@ protected function getRelationshipFromMethod($key, $camelKey) */ public function getMutatorMethod($key) { - $mutators = static::$mutatorCache[$this->clazz]; + $mutators = static::$mutatorCache[$this->klass]; return isset($mutators[$key]) ? $mutators[$key] : null; } From 3998d011ac02fc2a15f39c4ace57daee43dfc6ba Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 11:52:02 +0100 Subject: [PATCH 479/577] Add hasNot and whereHasNot method --- Eloquent/Builder.php | 87 +++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 9d017cff5..e4d65a68d 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -26,14 +26,14 @@ class Builder { * * @var array */ - protected $eagerLoad = array(); + protected $eagerLoad = []; /** * All of the registered builder macros. * * @var array */ - protected $macros = array(); + protected $macros = []; /** * A replacement for the typical delete function. @@ -47,10 +47,10 @@ class Builder { * * @var array */ - protected $passthru = array( + protected $passthru = [ 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'count', 'min', 'max', 'avg', 'sum', 'exists', 'getBindings', - ); + ]; /** * Create a new Eloquent query builder instance. @@ -70,7 +70,7 @@ public function __construct(QueryBuilder $query) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function find($id, $columns = array('*')) + public function find($id, $columns = ['*']) { if (is_array($id)) { @@ -89,7 +89,7 @@ public function find($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|Collection|static */ - public function findMany($id, $columns = array('*')) + public function findMany($id, $columns = ['*']) { if (empty($id)) return $this->model->newCollection(); @@ -107,7 +107,7 @@ public function findMany($id, $columns = array('*')) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function findOrFail($id, $columns = array('*')) + public function findOrFail($id, $columns = ['*']) { if ( ! is_null($model = $this->find($id, $columns))) return $model; @@ -120,7 +120,7 @@ public function findOrFail($id, $columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function first($columns = array('*')) + public function first($columns = ['*']) { return $this->take(1)->get($columns)->first(); } @@ -133,7 +133,7 @@ public function first($columns = array('*')) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function firstOrFail($columns = array('*')) + public function firstOrFail($columns = ['*']) { if ( ! is_null($model = $this->first($columns))) return $model; @@ -146,7 +146,7 @@ public function firstOrFail($columns = array('*')) * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ - public function get($columns = array('*')) + public function get($columns = ['*']) { $models = $this->getModels($columns); @@ -169,7 +169,7 @@ public function get($columns = array('*')) */ public function pluck($column) { - $result = $this->first(array($column)); + $result = $this->first([$column]); if ($result) return $result->{$column}; } @@ -216,7 +216,7 @@ public function lists($column, $key = null) { foreach ($results as $key => &$value) { - $fill = array($column => $value); + $fill = [$column => $value]; $value = $this->model->newFromBuilder($fill)->$column; } @@ -232,7 +232,7 @@ public function lists($column, $key = null) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function paginate($perPage = null, $columns = array('*')) + public function paginate($perPage = null, $columns = ['*']) { $perPage = $perPage ?: $this->model->getPerPage(); @@ -292,7 +292,7 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function simplePaginate($perPage = null, $columns = array('*')) + public function simplePaginate($perPage = null, $columns = ['*']) { $paginator = $this->query->getConnection()->getPaginator(); @@ -324,7 +324,7 @@ public function update(array $values) * @param array $extra * @return int */ - public function increment($column, $amount = 1, array $extra = array()) + public function increment($column, $amount = 1, array $extra = []) { $extra = $this->addUpdatedAtColumn($extra); @@ -339,7 +339,7 @@ public function increment($column, $amount = 1, array $extra = array()) * @param array $extra * @return int */ - public function decrement($column, $amount = 1, array $extra = array()) + public function decrement($column, $amount = 1, array $extra = []) { $extra = $this->addUpdatedAtColumn($extra); @@ -403,7 +403,7 @@ public function onDelete(Closure $callback) * @param array $columns * @return \Illuminate\Database\Eloquent\Model[] */ - public function getModels($columns = array('*')) + public function getModels($columns = ['*']) { // First, we will simply get the raw results from the query builders which we // can use to populate an array with Eloquent models. We will pass columns @@ -412,7 +412,7 @@ public function getModels($columns = array('*')) $connection = $this->model->getConnectionName(); - $models = array(); + $models = []; // Once we have the results, we can spin through them and instantiate a fresh // model instance for each records we retrieved from the database. We will @@ -515,7 +515,7 @@ public function getRelation($relation) */ protected function nestedRelations($relation) { - $nested = array(); + $nested = []; // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations @@ -566,7 +566,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - call_user_func_array(array($this->query, 'where'), func_get_args()); + call_user_func_array([$this->query, 'where'], func_get_args()); } return $this; @@ -588,11 +588,11 @@ public function orWhere($column, $operator = null, $value = null) /** * Add a relationship count condition to the query. * - * @param string $relation - * @param string $operator - * @param int $count - * @param string $boolean - * @param \Closure $callback + * @param string $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) @@ -606,6 +606,20 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ return $this->addHasWhere($query, $relation, $operator, $count, $boolean); } + + /** + * Add a relationship count condition to the query + * + * @param string $relation + * @param string $boolean + * @param null $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function hasNot($relation, $boolean = 'and', $callback = null) + { + return $this->has($relation, '<', 1, $boolean, $callback); + } + /** * Add a relationship count condition to the query with where clauses. * @@ -620,6 +634,19 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count return $this->has($relation, $operator, $count, 'and', $callback); } + + /** + * Add a relationship count condition to the query with where clauses. + * + * @param string $relation + * @param \Closure $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function whereHasNot($relation, Closure $callback) + { + return $this->hasNot($relation, 'and', $callback); + } + /** * Add a relationship count condition to the query with an "or". * @@ -731,7 +758,7 @@ public function with($relations) */ protected function parseRelations(array $relations) { - $results = array(); + $results = []; foreach ($relations as $name => $constraints) { @@ -742,7 +769,7 @@ protected function parseRelations(array $relations) { $f = function() {}; - list($name, $constraints) = array($constraints, $f); + list($name, $constraints) = [$constraints, $f]; } // We need to separate out any nested includes. Which allows the developers @@ -765,7 +792,7 @@ protected function parseRelations(array $relations) */ protected function parseNested($name, $results) { - $progress = array(); + $progress = []; // If the relation has already been set on the result array, we will not set it // again, since that would override any constraints that were already placed @@ -794,7 +821,7 @@ protected function callScope($scope, $parameters) { array_unshift($parameters, $this); - return call_user_func_array(array($this->model, $scope), $parameters) ?: $this; + return call_user_func_array([$this->model, $scope], $parameters) ?: $this; } /** @@ -907,7 +934,7 @@ public function __call($method, $parameters) return $this->callScope($scope, $parameters); } - $result = call_user_func_array(array($this->query, $method), $parameters); + $result = call_user_func_array([$this->query, $method], $parameters); return in_array($method, $this->passthru) ? $result : $this; } From a1bc97709ccbe45b0e88f48b7ff56e1c19e731fa Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 13:34:58 +0100 Subject: [PATCH 480/577] Add hasNot and whereHasNot method --- Eloquent/Builder.php | 75 ++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index e4d65a68d..227bbe725 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -26,14 +26,14 @@ class Builder { * * @var array */ - protected $eagerLoad = []; + protected $eagerLoad = array(); /** * All of the registered builder macros. * * @var array */ - protected $macros = []; + protected $macros = array(); /** * A replacement for the typical delete function. @@ -47,10 +47,10 @@ class Builder { * * @var array */ - protected $passthru = [ + protected $passthru = array( 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'count', 'min', 'max', 'avg', 'sum', 'exists', 'getBindings', - ]; + ); /** * Create a new Eloquent query builder instance. @@ -70,7 +70,7 @@ public function __construct(QueryBuilder $query) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function find($id, $columns = ['*']) + public function find($id, $columns = array('*')) { if (is_array($id)) { @@ -89,7 +89,7 @@ public function find($id, $columns = ['*']) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|Collection|static */ - public function findMany($id, $columns = ['*']) + public function findMany($id, $columns = array('*')) { if (empty($id)) return $this->model->newCollection(); @@ -107,7 +107,7 @@ public function findMany($id, $columns = ['*']) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function findOrFail($id, $columns = ['*']) + public function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = $this->find($id, $columns))) return $model; @@ -120,7 +120,7 @@ public function findOrFail($id, $columns = ['*']) * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static|null */ - public function first($columns = ['*']) + public function first($columns = array('*')) { return $this->take(1)->get($columns)->first(); } @@ -133,7 +133,7 @@ public function first($columns = ['*']) * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function firstOrFail($columns = ['*']) + public function firstOrFail($columns = array('*')) { if ( ! is_null($model = $this->first($columns))) return $model; @@ -146,7 +146,7 @@ public function firstOrFail($columns = ['*']) * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ - public function get($columns = ['*']) + public function get($columns = array('*')) { $models = $this->getModels($columns); @@ -169,7 +169,7 @@ public function get($columns = ['*']) */ public function pluck($column) { - $result = $this->first([$column]); + $result = $this->first(array($column)); if ($result) return $result->{$column}; } @@ -216,7 +216,7 @@ public function lists($column, $key = null) { foreach ($results as $key => &$value) { - $fill = [$column => $value]; + $fill = array($column => $value); $value = $this->model->newFromBuilder($fill)->$column; } @@ -232,7 +232,7 @@ public function lists($column, $key = null) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function paginate($perPage = null, $columns = ['*']) + public function paginate($perPage = null, $columns = array('*')) { $perPage = $perPage ?: $this->model->getPerPage(); @@ -292,7 +292,7 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function simplePaginate($perPage = null, $columns = ['*']) + public function simplePaginate($perPage = null, $columns = array('*')) { $paginator = $this->query->getConnection()->getPaginator(); @@ -324,7 +324,7 @@ public function update(array $values) * @param array $extra * @return int */ - public function increment($column, $amount = 1, array $extra = []) + public function increment($column, $amount = 1, array $extra = array()) { $extra = $this->addUpdatedAtColumn($extra); @@ -339,7 +339,7 @@ public function increment($column, $amount = 1, array $extra = []) * @param array $extra * @return int */ - public function decrement($column, $amount = 1, array $extra = []) + public function decrement($column, $amount = 1, array $extra = array()) { $extra = $this->addUpdatedAtColumn($extra); @@ -403,7 +403,7 @@ public function onDelete(Closure $callback) * @param array $columns * @return \Illuminate\Database\Eloquent\Model[] */ - public function getModels($columns = ['*']) + public function getModels($columns = array('*')) { // First, we will simply get the raw results from the query builders which we // can use to populate an array with Eloquent models. We will pass columns @@ -412,7 +412,7 @@ public function getModels($columns = ['*']) $connection = $this->model->getConnectionName(); - $models = []; + $models = array(); // Once we have the results, we can spin through them and instantiate a fresh // model instance for each records we retrieved from the database. We will @@ -515,7 +515,7 @@ public function getRelation($relation) */ protected function nestedRelations($relation) { - $nested = []; + $nested = array(); // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations @@ -566,7 +566,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } else { - call_user_func_array([$this->query, 'where'], func_get_args()); + call_user_func_array(array($this->query, 'where'), func_get_args()); } return $this; @@ -588,11 +588,11 @@ public function orWhere($column, $operator = null, $value = null) /** * Add a relationship count condition to the query. * - * @param string $relation - * @param string $operator - * @param int $count - * @param string $boolean - * @param \Closure $callback + * @param string $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) @@ -606,7 +606,6 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ return $this->addHasWhere($query, $relation, $operator, $count, $boolean); } - /** * Add a relationship count condition to the query * @@ -623,10 +622,10 @@ public function hasNot($relation, $boolean = 'and', $callback = null) /** * Add a relationship count condition to the query with where clauses. * - * @param string $relation + * @param string $relation * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $operator + * @param int $count * @return \Illuminate\Database\Eloquent\Builder|static */ public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -641,7 +640,7 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count * @param string $relation * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static - */ + */ public function whereHasNot($relation, Closure $callback) { return $this->hasNot($relation, 'and', $callback); @@ -758,7 +757,7 @@ public function with($relations) */ protected function parseRelations(array $relations) { - $results = []; + $results = array(); foreach ($relations as $name => $constraints) { @@ -769,7 +768,7 @@ protected function parseRelations(array $relations) { $f = function() {}; - list($name, $constraints) = [$constraints, $f]; + list($name, $constraints) = array($constraints, $f); } // We need to separate out any nested includes. Which allows the developers @@ -792,7 +791,7 @@ protected function parseRelations(array $relations) */ protected function parseNested($name, $results) { - $progress = []; + $progress = array(); // If the relation has already been set on the result array, we will not set it // again, since that would override any constraints that were already placed @@ -803,8 +802,8 @@ protected function parseNested($name, $results) if ( ! isset($results[$last = implode('.', $progress)])) { - $results[$last] = function() {}; - } + $results[$last] = function() {}; + } } return $results; @@ -821,7 +820,7 @@ protected function callScope($scope, $parameters) { array_unshift($parameters, $this); - return call_user_func_array([$this->model, $scope], $parameters) ?: $this; + return call_user_func_array(array($this->model, $scope), $parameters) ?: $this; } /** @@ -934,7 +933,7 @@ public function __call($method, $parameters) return $this->callScope($scope, $parameters); } - $result = call_user_func_array([$this->query, $method], $parameters); + $result = call_user_func_array(array($this->query, $method), $parameters); return in_array($method, $this->passthru) ? $result : $this; } @@ -949,4 +948,4 @@ public function __clone() $this->query = clone $this->query; } -} +} \ No newline at end of file From e34a6e6b0590c7b9a77c212e2f2a7f5013fb08b8 Mon Sep 17 00:00:00 2001 From: Aleksandar Babic Date: Wed, 17 Dec 2014 13:56:29 +0100 Subject: [PATCH 481/577] Use ConnectionInterface instead of implementation This will allow developers to use custom connection implementation. --- ConnectionResolver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ConnectionResolver.php b/ConnectionResolver.php index 05c28e8fb..79469b20e 100755 --- a/ConnectionResolver.php +++ b/ConnectionResolver.php @@ -34,7 +34,7 @@ public function __construct(array $connections = array()) * Get a database connection instance. * * @param string $name - * @return \Illuminate\Database\Connection + * @return \Illuminate\Database\ConnectionInterface */ public function connection($name = null) { @@ -47,10 +47,10 @@ public function connection($name = null) * Add a connection to the resolver. * * @param string $name - * @param \Illuminate\Database\Connection $connection + * @param \Illuminate\Database\ConnectionInterface $connection * @return void */ - public function addConnection($name, Connection $connection) + public function addConnection($name, ConnectionInterface $connection) { $this->connections[$name] = $connection; } From f13eff6eb09283cad18d67eccb43f1de4a68390d Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 14:13:22 +0100 Subject: [PATCH 482/577] Match with Laravel Code Style rules --- Eloquent/Builder.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 227bbe725..5dc98605a 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -607,11 +607,11 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ } /** - * Add a relationship count condition to the query + * Add a relationship count condition to the query. * - * @param string $relation - * @param string $boolean - * @param null $callback + * @param string $relation + * @param string $boolean + * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function hasNot($relation, $boolean = 'and', $callback = null) @@ -948,4 +948,4 @@ public function __clone() $this->query = clone $this->query; } -} \ No newline at end of file +} From a6b176a9dc5da1eed105b82e9ffb6c209ce5b760 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 14:14:56 +0100 Subject: [PATCH 483/577] Add new line at the end of the file --- Eloquent/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 5dc98605a..8539fac91 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -949,3 +949,4 @@ public function __clone() } } + From faf585de520417a8d1b0dc1a58ac5ebaed20ea4d Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 14:18:55 +0100 Subject: [PATCH 484/577] Remove useless line break --- Eloquent/Builder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 8539fac91..ff0a24ff7 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -633,7 +633,6 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count return $this->has($relation, $operator, $count, 'and', $callback); } - /** * Add a relationship count condition to the query with where clauses. * From a02a9ff404820b4766ae714b9f2759909d818ff6 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 14:57:08 +0100 Subject: [PATCH 485/577] Remove last endl --- Eloquent/Builder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index ff0a24ff7..332cc09ca 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -948,4 +948,3 @@ public function __clone() } } - From 6dbcbfe085b438a050c622fe545c9dcce574e7ca Mon Sep 17 00:00:00 2001 From: Koss Date: Wed, 17 Dec 2014 10:38:01 +0200 Subject: [PATCH 486/577] Fixed Query\Builder call to undefined method hasGetMutator when using lists method. When using lists method in Query\Builder: Call to undefined method Illuminate\Database\Query\Builder::hasGetMutator(). Need new method getMutatorMethod Proposed changes fix issue. Signed-off-by: Graham Campbell --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 9d017cff5..7ef9ac109 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -212,7 +212,7 @@ public function lists($column, $key = null) // If the model has a mutator for the requested column, we will spin through // the results and mutate the values so that the mutated version of these // columns are returned as you would expect from these Eloquent models. - if ($this->model->hasGetMutator($column)) + if ($this->model->getMutatorMethod($column)) { foreach ($results as $key => &$value) { From e86b980fbc774e699279ce8c22180e6e4a58fdf0 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 14:48:48 +0000 Subject: [PATCH 487/577] Fixed a bc break due to the deletion of hasGetMutator Signed-off-by: Graham Campbell --- Eloquent/Model.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 086e75bac..1f166025a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2517,6 +2517,19 @@ protected function getRelationshipFromMethod($key, $camelKey) return $this->relations[$key] = $relations->getResults(); } + /** + * Determine if a get mutator exists for an attribute. + * + * @deprecated Deprecated since version 4.2.13, to be removed in 5.0.0. + * + * @param string $key + * @return bool + */ + public function hasGetMutator($key) + { + return $this->getMutatorMethod($key); + } + /** * Get the method name if a get mutator exists for an attribute. * From 7af96e2731e1d52ae98ff6e35560a8e733972325 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 15:00:06 +0000 Subject: [PATCH 488/577] Be consistent with types --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 1f166025a..979007b40 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2527,14 +2527,14 @@ protected function getRelationshipFromMethod($key, $camelKey) */ public function hasGetMutator($key) { - return $this->getMutatorMethod($key); + return $this->getMutatorMethod($key) !== null; } /** * Get the method name if a get mutator exists for an attribute. * * @param string $key - * @return bool + * @return string|null */ public function getMutatorMethod($key) { From d21cd5b1aeaa377888ed396ea3e3f4a95717bd66 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 15:39:25 +0000 Subject: [PATCH 489/577] Removed deprecation annotation --- Eloquent/Model.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 979007b40..88b32c86e 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2520,8 +2520,6 @@ protected function getRelationshipFromMethod($key, $camelKey) /** * Determine if a get mutator exists for an attribute. * - * @deprecated Deprecated since version 4.2.13, to be removed in 5.0.0. - * * @param string $key * @return bool */ From 0bde514dccd70379d78e66ae002aa5fac808d095 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 15:41:57 +0000 Subject: [PATCH 490/577] Revert incorrect fixes --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 7ef9ac109..9d017cff5 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -212,7 +212,7 @@ public function lists($column, $key = null) // If the model has a mutator for the requested column, we will spin through // the results and mutate the values so that the mutated version of these // columns are returned as you would expect from these Eloquent models. - if ($this->model->getMutatorMethod($column)) + if ($this->model->hasGetMutator($column)) { foreach ($results as $key => &$value) { From 3081df2ca6faf35ff65f15e474290879b3b19915 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 11:25:44 -0600 Subject: [PATCH 491/577] Check for joins with adding deleted at clause for soft deletes. --- Eloquent/SoftDeletingScope.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Eloquent/SoftDeletingScope.php b/Eloquent/SoftDeletingScope.php index c6903cdd4..b4d26ac62 100644 --- a/Eloquent/SoftDeletingScope.php +++ b/Eloquent/SoftDeletingScope.php @@ -65,7 +65,7 @@ public function extend(Builder $builder) $builder->onDelete(function(Builder $builder) { - $column = $builder->getModel()->getDeletedAtColumn(); + $column = $this->getDeletedAtColumn($builder); return $builder->update(array( $column => $builder->getModel()->freshTimestampString() @@ -73,6 +73,24 @@ public function extend(Builder $builder) }); } + /** + * Get the "deleted at" column for the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return string + */ + protected function getDeletedAtColumn(Builder $builder) + { + if (count($builder->getQuery()->joins) > 0) + { + return $builder->getModel()->getQualifiedDeletedAtColumn(); + } + else + { + return $builder->getModel()->getDeletedAtColumn(); + } + } + /** * Add the force delete extension to the builder. * From 1ad967654d2145fe89e1920ee433db30b8b75e1a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 11:26:35 -0600 Subject: [PATCH 492/577] Check for joins. --- Eloquent/SoftDeletingScope.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Eloquent/SoftDeletingScope.php b/Eloquent/SoftDeletingScope.php index f5d1f4816..61c5d5cbc 100644 --- a/Eloquent/SoftDeletingScope.php +++ b/Eloquent/SoftDeletingScope.php @@ -65,7 +65,7 @@ public function extend(Builder $builder) $builder->onDelete(function(Builder $builder) { - $column = $builder->getModel()->getDeletedAtColumn(); + $column = $this->getDeletedAtColumn($builder); return $builder->update(array( $column => $builder->getModel()->freshTimestampString() @@ -73,6 +73,24 @@ public function extend(Builder $builder) }); } + /** + * Get the "deleted at" column for the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return string + */ + protected function getDeletedAtColumn(Builder $builder) + { + if (count($builder->getQuery()->joins) > 0) + { + return $builder->getModel()->getQualifiedDeletedAtColumn(); + } + else + { + return $builder->getModel()->getDeletedAtColumn(); + } + } + /** * Add the force delete extension to the builder. * From e33aa9ffa554d04ca90449001cce5bac2ea85c11 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 17 Dec 2014 18:46:43 +0100 Subject: [PATCH 493/577] Change allignement --- Eloquent/Builder.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 332cc09ca..1e36f1af8 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -595,7 +595,7 @@ public function orWhere($column, $operator = null, $value = null) * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ - public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) + public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) { $relation = $this->getHasRelationQuery($relation); @@ -609,12 +609,12 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ /** * Add a relationship count condition to the query. * - * @param string $relation - * @param string $boolean + * @param string $relation + * @param string $boolean * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ - public function hasNot($relation, $boolean = 'and', $callback = null) + public function hasNot($relation, $boolean = 'and', Closure $callback = null) { return $this->has($relation, '<', 1, $boolean, $callback); } @@ -622,10 +622,10 @@ public function hasNot($relation, $boolean = 'and', $callback = null) /** * Add a relationship count condition to the query with where clauses. * - * @param string $relation + * @param string $relation * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $operator + * @param int $count * @return \Illuminate\Database\Eloquent\Builder|static */ public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -636,7 +636,7 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count /** * Add a relationship count condition to the query with where clauses. * - * @param string $relation + * @param string $relation * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ From 707b2e0d2e73e3864c936f41ebfe57b8a7faeec1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 13:17:55 -0600 Subject: [PATCH 494/577] Rename some methods. --- Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 1e36f1af8..d33e77843 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -614,7 +614,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ - public function hasNot($relation, $boolean = 'and', Closure $callback = null) + public function doesntHave($relation, $boolean = 'and', Closure $callback = null) { return $this->has($relation, '<', 1, $boolean, $callback); } @@ -640,7 +640,7 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static */ - public function whereHasNot($relation, Closure $callback) + public function whereDoesntHave($relation, Closure $callback) { return $this->hasNot($relation, 'and', $callback); } From 266688f3b34940f4e8c28a6e22083c843bef53ce Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 20:39:51 +0000 Subject: [PATCH 495/577] Fixed some docblocks --- Migrations/MigrationCreator.php | 2 +- Query/Builder.php | 2 +- Query/JoinClause.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index de1fc5be5..e70b627b5 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -106,7 +106,7 @@ protected function populateStub($name, $stub, $table) /** * Get the class name of a migration name. * - * @param string $name + * @param string $name * @return string */ protected function getClassName($name) diff --git a/Query/Builder.php b/Query/Builder.php index 79e760831..c9c0a1fbf 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1198,7 +1198,7 @@ public function forPage($page, $perPage = 15) * Add a union statement to the query. * * @param \Illuminate\Database\Query\Builder|\Closure $query - * @param bool $all + * @param bool $all * @return \Illuminate\Database\Query\Builder|static */ public function union($query, $all = false) diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 3cca966bd..5834cf4b6 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -106,7 +106,7 @@ public function orWhere($first, $operator, $second) * Add an "on where is null" clause to the join * * @param $column - * @param string $boolean + * @param string $boolean * @return \Illuminate\Database\Query\JoinClause */ public function whereNull($column, $boolean = 'and') From a1cef07b40825df953d3892b2fe829aec0c94369 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 17 Dec 2014 20:42:06 +0000 Subject: [PATCH 496/577] Added missing types --- Connection.php | 2 +- Eloquent/Relations/BelongsToMany.php | 2 +- Query/JoinClause.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Connection.php b/Connection.php index b8c6e4c4f..fd09205a9 100755 --- a/Connection.php +++ b/Connection.php @@ -709,7 +709,7 @@ protected function reconnectIfMissingConnection() * * @param string $query * @param array $bindings - * @param $time + * @param float|null $time * @return void */ public function logQuery($query, $bindings, $time = null) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index a220712a3..aeb41f6f3 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -579,7 +579,7 @@ public function createMany(array $records, array $joinings = array()) /** * Sync the intermediate tables with a list of IDs or collection of models. * - * @param $ids + * @param array $ids * @param bool $detaching * @return array */ diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 5834cf4b6..cea79ed4c 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -105,7 +105,7 @@ public function orWhere($first, $operator, $second) /** * Add an "on where is null" clause to the join * - * @param $column + * @param string $column * @param string $boolean * @return \Illuminate\Database\Query\JoinClause */ From 350541c7398a729edf98f3c88e6ab657e0863cd7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 15:01:33 -0600 Subject: [PATCH 497/577] Merging. --- Connection.php | 2 +- Eloquent/Relations/BelongsToMany.php | 2 +- Migrations/MigrationCreator.php | 2 +- Query/Builder.php | 2 +- Query/JoinClause.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Connection.php b/Connection.php index 1b257b8b7..9e00fc3f3 100755 --- a/Connection.php +++ b/Connection.php @@ -695,7 +695,7 @@ protected function reconnectIfMissingConnection() * * @param string $query * @param array $bindings - * @param $time + * @param float|null $time * @return void */ public function logQuery($query, $bindings, $time = null) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 733f2059b..f99b404fc 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -558,7 +558,7 @@ public function createMany(array $records, array $joinings = array()) /** * Sync the intermediate tables with a list of IDs or collection of models. * - * @param $ids + * @param array $ids * @param bool $detaching * @return array */ diff --git a/Migrations/MigrationCreator.php b/Migrations/MigrationCreator.php index de1fc5be5..e70b627b5 100755 --- a/Migrations/MigrationCreator.php +++ b/Migrations/MigrationCreator.php @@ -106,7 +106,7 @@ protected function populateStub($name, $stub, $table) /** * Get the class name of a migration name. * - * @param string $name + * @param string $name * @return string */ protected function getClassName($name) diff --git a/Query/Builder.php b/Query/Builder.php index c4198a4a9..bd261aae0 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1215,7 +1215,7 @@ public function forPage($page, $perPage = 15) * Add a union statement to the query. * * @param \Illuminate\Database\Query\Builder|\Closure $query - * @param bool $all + * @param bool $all * @return \Illuminate\Database\Query\Builder|static */ public function union($query, $all = false) diff --git a/Query/JoinClause.php b/Query/JoinClause.php index 3cca966bd..cea79ed4c 100755 --- a/Query/JoinClause.php +++ b/Query/JoinClause.php @@ -105,8 +105,8 @@ public function orWhere($first, $operator, $second) /** * Add an "on where is null" clause to the join * - * @param $column - * @param string $boolean + * @param string $column + * @param string $boolean * @return \Illuminate\Database\Query\JoinClause */ public function whereNull($column, $boolean = 'and') From 286b19272051b09dc727e34366e9553b1ac0930d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 17 Dec 2014 22:19:06 +0100 Subject: [PATCH 498/577] Fix some docblocks alignment --- Console/SeedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index 04d3e6d02..cba115b47 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -26,7 +26,7 @@ class SeedCommand extends Command { /** * The connection resolver instance. * - * @var \Illuminate\Database\ConnectionResolverInterface + * @var \Illuminate\Database\ConnectionResolverInterface */ protected $resolver; From 22f6350499926953939f288865542e31e93f81d0 Mon Sep 17 00:00:00 2001 From: janhartigan Date: Wed, 17 Dec 2014 19:25:06 -0800 Subject: [PATCH 499/577] allowing for camel and studly-cased mutator attributes --- Eloquent/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 88b32c86e..cafcdd3de 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2537,6 +2537,7 @@ public function hasGetMutator($key) public function getMutatorMethod($key) { $mutators = static::$mutatorCache[$this->klass]; + $key = snake_case($key); return isset($mutators[$key]) ? $mutators[$key] : null; } @@ -3171,4 +3172,4 @@ public function __wakeup() $this->bootIfNotBooted(); } -} +} \ No newline at end of file From 00adacfa2ffb688dcb983913c0c303bce24c079d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 22:00:52 -0600 Subject: [PATCH 500/577] Fix spacing. --- Eloquent/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index cafcdd3de..e876eca63 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2537,6 +2537,7 @@ public function hasGetMutator($key) public function getMutatorMethod($key) { $mutators = static::$mutatorCache[$this->klass]; + $key = snake_case($key); return isset($mutators[$key]) ? $mutators[$key] : null; @@ -3172,4 +3173,4 @@ public function __wakeup() $this->bootIfNotBooted(); } -} \ No newline at end of file +} From 061266af34763a61d3a2dbd10114087ebee343a7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 22:02:10 -0600 Subject: [PATCH 501/577] Fix conflicts. --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 70a2c0cd8..05cfa7295 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2661,6 +2661,8 @@ public function getMutatorMethod($key) { $mutators = static::$mutatorCache[$this->klass]; + $key = snake_case($key); + return isset($mutators[$key]) ? $mutators[$key] : null; } From 3a9d4e56eba64399081c23f0698462f3a07ff51e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 22:02:31 -0600 Subject: [PATCH 502/577] Remove snake_case. --- Eloquent/Model.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 05cfa7295..70a2c0cd8 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2661,8 +2661,6 @@ public function getMutatorMethod($key) { $mutators = static::$mutatorCache[$this->klass]; - $key = snake_case($key); - return isset($mutators[$key]) ? $mutators[$key] : null; } From fb26dbb057c86c49c02e6286b56699ae287dfc85 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 22:10:57 -0600 Subject: [PATCH 503/577] Put snake_case back in for now. --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 70a2c0cd8..05cfa7295 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2661,6 +2661,8 @@ public function getMutatorMethod($key) { $mutators = static::$mutatorCache[$this->klass]; + $key = snake_case($key); + return isset($mutators[$key]) ? $mutators[$key] : null; } From 01a9bad2e4b7b7d408cee8a421952dec458e8255 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 17 Dec 2014 23:02:43 -0600 Subject: [PATCH 504/577] Fix method name. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index d33e77843..58a295cca 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -642,7 +642,7 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count */ public function whereDoesntHave($relation, Closure $callback) { - return $this->hasNot($relation, 'and', $callback); + return $this->doesntHave($relation, 'and', $callback); } /** From 215cb51fcfebdb625cbd8ca4cacff587e98629cd Mon Sep 17 00:00:00 2001 From: Jamshed Javed Date: Thu, 18 Dec 2014 09:58:50 +0000 Subject: [PATCH 505/577] Limit backtrace frames to return --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e876eca63..95dbac0ea 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -786,7 +786,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat // of the time this will be what we desire to use for the relationships. if (is_null($relation)) { - list(, $caller) = debug_backtrace(false); + list(, $caller) = debug_backtrace(false, 2); $relation = $caller['function']; } @@ -826,7 +826,7 @@ public function morphTo($name = null, $type = null, $id = null) // use that to get both the class and foreign key that will be utilized. if (is_null($name)) { - list(, $caller) = debug_backtrace(false); + list(, $caller) = debug_backtrace(false, 2); $name = snake_case($caller['function']); } From 29e51b7cef44949816d6b9b7977611056a6ce963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Blanco?= Date: Thu, 18 Dec 2014 10:31:07 +0000 Subject: [PATCH 506/577] Adding getGuarded() getter. Is there any particular reason why this one has not been created initially? --- Eloquent/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index e876eca63..bc399431d 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2083,6 +2083,16 @@ public function fillable(array $fillable) return $this; } + + /** + * Get the guarded attributes for the model. + * + * @return array + */ + public function getGuarded() + { + return $this->guarded; + } /** * Set the guarded attributes for the model. From 4f3b4b6240b2113584be1994d5f6e3ada9178330 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 18 Dec 2014 09:28:55 +0000 Subject: [PATCH 507/577] Various database fixes --- Eloquent/Builder.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 58a295cca..87132a482 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -592,7 +592,7 @@ public function orWhere($column, $operator = null, $value = null) * @param string $operator * @param int $count * @param string $boolean - * @param \Closure $callback + * @param \Closure|null $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) @@ -611,7 +611,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C * * @param string $relation * @param string $boolean - * @param \Closure $callback + * @param \Closure|null $callback * @return \Illuminate\Database\Eloquent\Builder|static */ public function doesntHave($relation, $boolean = 'and', Closure $callback = null) @@ -622,10 +622,10 @@ public function doesntHave($relation, $boolean = 'and', Closure $callback = null /** * Add a relationship count condition to the query with where clauses. * - * @param string $relation + * @param string $relation * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $operator + * @param int $count * @return \Illuminate\Database\Eloquent\Builder|static */ public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -637,10 +637,10 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count * Add a relationship count condition to the query with where clauses. * * @param string $relation - * @param \Closure $callback + * @param \Closure|null $callback * @return \Illuminate\Database\Eloquent\Builder|static */ - public function whereDoesntHave($relation, Closure $callback) + public function whereDoesntHave($relation, Closure $callback = null) { return $this->doesntHave($relation, 'and', $callback); } @@ -661,10 +661,10 @@ public function orHas($relation, $operator = '>=', $count = 1) /** * Add a relationship count condition to the query with where clauses and an "or". * - * @param string $relation + * @param string $relation * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $operator + * @param int $count * @return \Illuminate\Database\Eloquent\Builder|static */ public function orWhereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -697,8 +697,8 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, /** * Merge the "wheres" from a relation query to a has query. * - * @param \Illuminate\Database\Eloquent\Builder $hasQuery - * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @param \Illuminate\Database\Eloquent\Builder $hasQuery + * @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @return void */ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) @@ -812,7 +812,7 @@ protected function parseNested($name, $results) * Call the given model scope on the underlying model. * * @param string $scope - * @param array $parameters + * @param array $parameters * @return \Illuminate\Database\Query\Builder */ protected function callScope($scope, $parameters) @@ -892,7 +892,7 @@ public function setModel(Model $model) /** * Extend the builder with a given callback. * - * @param string $name + * @param string $name * @param \Closure $callback * @return void */ From a97f4dddc42f7f4b44a529aacc7629a9459963e0 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Thu, 18 Dec 2014 11:39:22 +0100 Subject: [PATCH 508/577] Fix the docblock for constructor --- Eloquent/Relations/HasManyThrough.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index f378ce660..6ff2c48c8 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -32,6 +32,7 @@ class HasManyThrough extends Relation { * Create a new has many relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Model $farParent * @param \Illuminate\Database\Eloquent\Model $parent * @param string $firstKey * @param string $secondKey From 193035a220cc2b77724d6845e12bf9862706fe36 Mon Sep 17 00:00:00 2001 From: janhartigan Date: Thu, 18 Dec 2014 15:28:27 -0800 Subject: [PATCH 509/577] fixing assignment bug in model isset method --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 6e8902480..c14369413 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -3116,7 +3116,7 @@ public function offsetUnset($offset) public function __isset($key) { return ((isset($this->attributes[$key]) || isset($this->relations[$key])) || - ($method = $this->getMutatorMethod($key) && ! is_null($this->getMutatedAttributeValue($key, $method)))); + (($method = $this->getMutatorMethod($key)) && ! is_null($this->getMutatedAttributeValue($key, $method)))); } /** From aa260d4e3cd8bba6dbd720ec470b57d487ed25c1 Mon Sep 17 00:00:00 2001 From: Jarek Tkaczyk Date: Fri, 19 Dec 2014 02:23:40 +0100 Subject: [PATCH 510/577] improve has for nested relations --- Eloquent/Builder.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 87132a482..e827a0e28 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -597,6 +597,11 @@ public function orWhere($column, $operator = null, $value = null) */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) { + if (strpos($relation, '.') !== false) + { + return $this->hasNested($relation, $operator, $count, $boolean, $callback); + } + $relation = $this->getHasRelationQuery($relation); $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this); @@ -606,6 +611,41 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C return $this->addHasWhere($query, $relation, $operator, $count, $boolean); } + /** + * Add nested relationship count conditions to the query. + * + * @param string $relations + * @param string $operator + * @param integer $count + * @param string $boolean + * @param \Closure $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + protected function hasNested($relations, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) + { + $relations = explode('.', $relations); + + // In order to nest "has", we need to add count relation constraints + // on the callback closure. We will do this by simply passing to + // closure its own reference, so it calls itself recursively. + $closure = function ($q) use (&$closure, &$relations, $operator, $count, $boolean, $callback) + { + // If the "relation" is specified using dot notation, we will assume + // that developer wants to check simple "has" on the intermediate + // relations and add constraints only on the furthermost query. + if (count($relations) > 1) + { + $q->whereHas(array_shift($relations), $closure); + } + else + { + $q->has(array_shift($relations), $operator, $count, $boolean, $callback); + } + }; + + return $this->whereHas(array_shift($relations), $closure); + } + /** * Add a relationship count condition to the query. * From dd8a777d6121e7c0c7686633ea28ef57311930be Mon Sep 17 00:00:00 2001 From: jongwoo Yoo Date: Fri, 19 Dec 2014 22:44:05 +0900 Subject: [PATCH 511/577] [4.2] Fix Query Builder GroupBy Method Doc Block --- Query/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Query/Builder.php b/Query/Builder.php index c9c0a1fbf..b9c34920d 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -997,6 +997,7 @@ protected function addDynamic($segment, $connector, $parameters, $index) /** * Add a "group by" clause to the query. * + * @param array|string $column,... * @return $this */ public function groupBy() From c5a3da3f596f103444e8b307450080630cc832ae Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 20 Dec 2014 14:52:31 +0100 Subject: [PATCH 512/577] Check FQN --- Connection.php | 6 ++++-- Connectors/ConnectionFactory.php | 7 ++++--- Connectors/SQLiteConnector.php | 4 +++- DatabaseManager.php | 3 ++- Eloquent/Model.php | 3 ++- Query/Builder.php | 12 +++++++----- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Connection.php b/Connection.php index 9e00fc3f3..1aee4a3bc 100755 --- a/Connection.php +++ b/Connection.php @@ -3,6 +3,8 @@ use PDO; use Closure; use DateTime; +use LogicException; +use RuntimeException; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Query\Processors\Processor; use Doctrine\DBAL\Connection as DoctrineConnection; @@ -674,7 +676,7 @@ public function reconnect() return call_user_func($this->reconnector, $this); } - throw new \LogicException("Lost connection and no reconnector available."); + throw new LogicException("Lost connection and no reconnector available."); } /** @@ -818,7 +820,7 @@ public function getReadPdo() public function setPdo($pdo) { if ($this->transactions >= 1) - throw new \RuntimeException("Can't swap PDO instance while within transaction."); + throw new RuntimeException("Can't swap PDO instance while within transaction."); $this->pdo = $pdo; diff --git a/Connectors/ConnectionFactory.php b/Connectors/ConnectionFactory.php index da2d3ff1c..37dd69fca 100755 --- a/Connectors/ConnectionFactory.php +++ b/Connectors/ConnectionFactory.php @@ -1,6 +1,7 @@ container->bound($key = "db.connector.{$config['driver']}")) @@ -187,7 +188,7 @@ public function createConnector(array $config) return new SqlServerConnector; } - throw new \InvalidArgumentException("Unsupported driver [{$config['driver']}]"); + throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]"); } /** @@ -224,7 +225,7 @@ protected function createConnection($driver, PDO $connection, $database, $prefix return new SqlServerConnection($connection, $database, $prefix, $config); } - throw new \InvalidArgumentException("Unsupported driver [$driver]"); + throw new InvalidArgumentException("Unsupported driver [$driver]"); } } diff --git a/Connectors/SQLiteConnector.php b/Connectors/SQLiteConnector.php index 596ef28b3..697a72b80 100755 --- a/Connectors/SQLiteConnector.php +++ b/Connectors/SQLiteConnector.php @@ -1,5 +1,7 @@ createConnection("sqlite:{$path}", $config, $options); diff --git a/DatabaseManager.php b/DatabaseManager.php index 3b8693b92..45cde61b5 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -1,6 +1,7 @@ primaryKey)) { - throw new \Exception("No primary key defined on model."); + throw new Exception("No primary key defined on model."); } if ($this->exists) diff --git a/Query/Builder.php b/Query/Builder.php index b9d6f9ba1..2928f50a6 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1,6 +1,8 @@ selectRaw('('.$query.') as '.$this->grammar->wrap($as), $bindings); @@ -451,7 +453,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } elseif ($this->invalidOperatorAndValue($operator, $value)) { - throw new \InvalidArgumentException("Value must be provided."); + throw new InvalidArgumentException("Value must be provided."); } // If the columns is actually a Closure instance, we will assume the developer @@ -1878,7 +1880,7 @@ public function setBindings(array $bindings, $type = 'where') { if ( ! array_key_exists($type, $this->bindings)) { - throw new \InvalidArgumentException("Invalid binding type: {$type}."); + throw new InvalidArgumentException("Invalid binding type: {$type}."); } $this->bindings[$type] = $bindings; @@ -1899,7 +1901,7 @@ public function addBinding($value, $type = 'where') { if ( ! array_key_exists($type, $this->bindings)) { - throw new \InvalidArgumentException("Invalid binding type: {$type}."); + throw new InvalidArgumentException("Invalid binding type: {$type}."); } if (is_array($value)) @@ -1987,7 +1989,7 @@ public function __call($method, $parameters) $className = get_class($this); - throw new \BadMethodCallException("Call to undefined method {$className}::{$method}()"); + throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); } } From 9833fc9e0297044047a699b06155dcedf25016e6 Mon Sep 17 00:00:00 2001 From: crynobone Date: Mon, 22 Dec 2014 21:25:38 +0800 Subject: [PATCH 513/577] [4.2] Fixes mutators implementation when $mutatorCache for given class is not available. Solves #6769 Signed-off-by: crynobone --- Eloquent/Model.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c14369413..39cb30be8 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2083,7 +2083,7 @@ public function fillable(array $fillable) return $this; } - + /** * Get the guarded attributes for the model. * @@ -2546,11 +2546,9 @@ public function hasGetMutator($key) */ public function getMutatorMethod($key) { - $mutators = static::$mutatorCache[$this->klass]; - $key = snake_case($key); - return isset($mutators[$key]) ? $mutators[$key] : null; + return array_get(static::$mutatorCache, "{$this->klass}.{$key}"); } /** From aea8e53a6cb6d320c86da290f8a4c95b2b07e22f Mon Sep 17 00:00:00 2001 From: crynobone Date: Mon, 22 Dec 2014 22:10:43 +0800 Subject: [PATCH 514/577] Additional fixes based on comment. Signed-off-by: crynobone --- Eloquent/Model.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 39cb30be8..c7b34ff02 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2303,9 +2303,9 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->getArrayableAppends() as $key) { - $attributes[$key] = $this->mutateAttributeForArray( - $this->getMutatorMethod($key), null - ); + $getMutator = $this->getMutatorMethod($key) ?: $key; + + $attributes[$key] = $this->mutateAttributeForArray($getMutator, null); } return $attributes; @@ -2463,7 +2463,9 @@ protected function getAttributeValue($key) // it returns as the value, which is useful for transforming values on // retrieval from the model to a form that is more useful for usage. $getMutator = $this->getMutatorMethod($key); - if ($getMutator) { + + if ($getMutator) + { return $this->getMutatedAttributeValue($key, $getMutator); } // If the attribute is listed as a date, we will convert it to a DateTime From e2a5f91c7e9aac958ebb5a8ec716ce87fe6f24b5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 22 Dec 2014 09:27:49 -0600 Subject: [PATCH 515/577] Spacing. --- Eloquent/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c7b34ff02..5d6f9076a 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2468,6 +2468,7 @@ protected function getAttributeValue($key) { return $this->getMutatedAttributeValue($key, $getMutator); } + // If the attribute is listed as a date, we will convert it to a DateTime // instance on retrieval, which makes it quite convenient to work with // date fields without having to create a mutator for each property. From e72b74077351a911ab889d9117fbc87e973a4c5e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 22 Dec 2014 09:29:20 -0600 Subject: [PATCH 516/577] Use asset. --- Eloquent/Model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 5d6f9076a..d5f18c070 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2551,7 +2551,10 @@ public function getMutatorMethod($key) { $key = snake_case($key); - return array_get(static::$mutatorCache, "{$this->klass}.{$key}"); + if (isset(static::$mutatorCache[$this->klass][$key])) + { + return static::$mutatorCache[$this->klass][$key]; + } } /** From 5d07587a51b13224cdda6417fbc25e9c13d276c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 22 Dec 2014 14:55:49 -0600 Subject: [PATCH 517/577] Reverse change that has caused ridiculous problems. --- Eloquent/Model.php | 108 ++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 76 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index d5f18c070..473a6e142 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -234,14 +234,6 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ const UPDATED_AT = 'updated_at'; - - /** - * The name of this class. Cached to avoid calls to get_class + studly_case. - * - * @var string - */ - protected $klass; - /** * Create a new Eloquent model instance. * @@ -250,8 +242,6 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ public function __construct(array $attributes = array()) { - $this->klass = get_class($this); - $this->bootIfNotBooted(); $this->syncOriginal(); @@ -266,9 +256,11 @@ public function __construct(array $attributes = array()) */ protected function bootIfNotBooted() { - if ( ! isset(static::$booted[$this->klass])) + $class = get_class($this); + + if ( ! isset(static::$booted[$class])) { - static::$booted[$this->klass] = true; + static::$booted[$class] = true; $this->fireModelEvent('booting', false); @@ -298,7 +290,7 @@ protected static function boot() { if (static::$snakeAttributes) $matches[1] = snake_case($matches[1]); - static::$mutatorCache[$class][lcfirst($matches[1])] = $matches[0]; + static::$mutatorCache[$class][] = lcfirst($matches[1]); } } @@ -401,8 +393,6 @@ public static function observe($class) */ public function fill(array $attributes) { - if (empty($attributes)) return $this; - $totallyGuarded = $this->totallyGuarded(); foreach ($this->fillableFromArray($attributes) as $key => $value) @@ -625,6 +615,18 @@ public static function on($connection = null) return $instance->newQuery(); } + /** + * Begin querying the model on the write connection. + * + * @return \Illuminate\Database\Query\Builder + */ + public static function onWriteConnection() + { + $instance = new static; + + return $instance->newQuery()->useWritePdo(); + } + /** * Get all of the models from the database. * @@ -654,18 +656,6 @@ public static function find($id, $columns = array('*')) return $instance->newQuery()->find($id, $columns); } - /** - * Begin querying the model on the write connection. - * - * @return \Illuminate\Database\Query\Builder - */ - public static function onWriteConnection() - { - $instance = new static; - - return $instance->newQuery()->useWritePdo(); - } - /** * Find a model by its primary key or return new static. * @@ -2085,7 +2075,7 @@ public function fillable(array $fillable) } /** - * Get the guarded attributes for the model. + * get the guarded attributes for the model. * * @return array */ @@ -2289,12 +2279,12 @@ public function attributesToArray() // We want to spin through all the mutated attributes for this model and call // the mutator for the attribute. We cache off every mutated attributes so // we don't have to constantly check on attributes that actually change. - foreach ($this->getMutatedAttributes() as $key => $method) + foreach ($this->getMutatedAttributes() as $key) { if ( ! array_key_exists($key, $attributes)) continue; $attributes[$key] = $this->mutateAttributeForArray( - $method, $attributes[$key] + $key, $attributes[$key] ); } @@ -2303,9 +2293,7 @@ public function attributesToArray() // when we need to array or JSON the model for convenience to the coder. foreach ($this->getArrayableAppends() as $key) { - $getMutator = $this->getMutatorMethod($key) ?: $key; - - $attributes[$key] = $this->mutateAttributeForArray($getMutator, null); + $attributes[$key] = $this->mutateAttributeForArray($key, null); } return $attributes; @@ -2425,7 +2413,7 @@ public function getAttribute($key) // If the key references an attribute, we can just go ahead and return the // plain attribute value from the model. This allows every attribute to // be dynamically accessed through the _get method without accessors. - if ($inAttributes || $this->getMutatorMethod($key)) + if ($inAttributes || $this->hasGetMutator($key)) { return $this->getAttributeValue($key); } @@ -2462,11 +2450,9 @@ protected function getAttributeValue($key) // If the attribute has a get mutator, we will call that then return what // it returns as the value, which is useful for transforming values on // retrieval from the model to a form that is more useful for usage. - $getMutator = $this->getMutatorMethod($key); - - if ($getMutator) + if ($this->hasGetMutator($key)) { - return $this->getMutatedAttributeValue($key, $getMutator); + return $this->mutateAttribute($key, $value); } // If the attribute is listed as a date, we will convert it to a DateTime @@ -2480,20 +2466,6 @@ protected function getAttributeValue($key) return $value; } - /** - * Get the mutated value of an attribute. - * - * @param string $key - * @param string $mutatorMethod - * @return mixed - */ - protected function getMutatedAttributeValue($key, $mutatorMethod) - { - $value = $this->getAttributeFromArray($key); - - return $this->mutateAttribute($mutatorMethod, $value); - } - /** * Get an attribute from the $attributes array. * @@ -2538,47 +2510,31 @@ protected function getRelationshipFromMethod($key, $camelKey) */ public function hasGetMutator($key) { - return $this->getMutatorMethod($key) !== null; - } - - /** - * Get the method name if a get mutator exists for an attribute. - * - * @param string $key - * @return string|null - */ - public function getMutatorMethod($key) - { - $key = snake_case($key); - - if (isset(static::$mutatorCache[$this->klass][$key])) - { - return static::$mutatorCache[$this->klass][$key]; - } + return method_exists($this, 'get'.studly_case($key).'Attribute'); } /** * Get the value of an attribute using its mutator. * - * @param string $mutatorMethod + * @param string $key * @param mixed $value * @return mixed */ - protected function mutateAttribute($mutatorMethod, $value) + protected function mutateAttribute($key, $value) { - return $this->{$mutatorMethod}($value); + return $this->{'get'.studly_case($key).'Attribute'}($value); } /** * Get the value of an attribute using its mutator for array conversion. * - * @param string $mutatorMethod + * @param string $key * @param mixed $value * @return mixed */ - protected function mutateAttributeForArray($mutatorMethod, $value) + protected function mutateAttributeForArray($key, $value) { - $value = $this->mutateAttribute($mutatorMethod, $value); + $value = $this->mutateAttribute($key, $value); return $value instanceof ArrayableInterface ? $value->toArray() : $value; } @@ -3120,7 +3076,7 @@ public function offsetUnset($offset) public function __isset($key) { return ((isset($this->attributes[$key]) || isset($this->relations[$key])) || - (($method = $this->getMutatorMethod($key)) && ! is_null($this->getMutatedAttributeValue($key, $method)))); + ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))); } /** From 675362cd903f6bbea8ee52ba5438aa616f8d988c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 22 Dec 2014 15:44:23 -0600 Subject: [PATCH 518/577] Fix casing. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 7dc9a7fa4..1187dbc2b 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2202,7 +2202,7 @@ public function fillable(array $fillable) } /** - * get the guarded attributes for the model. + * Get the guarded attributes for the model. * * @return array */ From 845a2e132cfd6cd30f7347c04ab08f4b0e944123 Mon Sep 17 00:00:00 2001 From: Patrick Carlo-Hickman Date: Tue, 23 Dec 2014 04:35:27 +0000 Subject: [PATCH 519/577] Fix Eloquent Model push method due to Eloquent Collection changes. --- Eloquent/Model.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 1187dbc2b..e0277fc13 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1471,7 +1471,12 @@ public function push() // us to recurs into all of these nested relations for this model instance. foreach ($this->relations as $models) { - $models = is_array($models) ? $models : array($models); + // Models can be a collection of models (hasMany), an individual model (hasOne), + // or null (non-existing hasOne). Convert to an array. + $models = $models instanceof Collection ? $models->all() : array($models); + + // Filter out any null entries from non-existing relationships. + $models = array_filter($models); foreach ($models as $model) { From 8352c9ca3895af5d77a4c1cb2a87638954114916 Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Tue, 23 Dec 2014 14:42:14 +0000 Subject: [PATCH 520/577] Casting of Eloquent attributes to native types. --- Eloquent/Model.php | 115 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 473a6e142..b6a150b68 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -129,6 +129,13 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa */ protected $dates = array(); + /** + * The attributes that should be casted to native types. + * + * @var array + */ + protected $casts = array(); + /** * The relationships that should be touched on save. * @@ -2276,10 +2283,12 @@ public function attributesToArray() $attributes[$key] = (string) $this->asDateTime($attributes[$key]); } + $mutatedAttributes = $this->getMutatedAttributes(); + // We want to spin through all the mutated attributes for this model and call // the mutator for the attribute. We cache off every mutated attributes so // we don't have to constantly check on attributes that actually change. - foreach ($this->getMutatedAttributes() as $key) + foreach ($mutatedAttributes as $key) { if ( ! array_key_exists($key, $attributes)) continue; @@ -2288,6 +2297,14 @@ public function attributesToArray() ); } + foreach ($this->casts as $key => $value) + { + if ( ! array_key_exists($key, $attributes)) continue; + if (in_array($key, $mutatedAttributes)) continue; + + $attributes[$key] = $this->castAttribute($key, $attributes[$key]); + } + // Here we will grab all of the appended, calculated attributes to this model // as these attributes are not really in the attributes array, but are run // when we need to array or JSON the model for convenience to the coder. @@ -2455,6 +2472,14 @@ protected function getAttributeValue($key) return $this->mutateAttribute($key, $value); } + // If the attribute exists within the cast array, we will convert it to + // an appropriate native PHP type dependant upon the associated value + // given with the key in the pair. Dayle made this comment line up. + if ($this->hasCast($key)) + { + $value = $this->castAttribute($key, $value); + } + // If the attribute is listed as a date, we will convert it to a DateTime // instance on retrieval, which makes it quite convenient to work with // date fields without having to create a mutator for each property. @@ -2539,6 +2564,89 @@ protected function mutateAttributeForArray($key, $value) return $value instanceof ArrayableInterface ? $value->toArray() : $value; } + /** + * Determine whether an attribute should be casted to a native type. + * + * @param string $key + * @return boolean + */ + protected function hasCast($key) + { + return array_key_exists($key, $this->casts); + } + + /** + * Determine whether a value is JSON castable for inbound manipulation. + * + * @param string $key + * @return boolean + */ + protected function isJsonCastable($key) + { + if ($this->hasCast($key)) + { + return $this->getCastType($key) === 'json'; + } + return false; + } + + /** + * Get the type of cast for a model attribute. + * + * @param string $key + * @return string + */ + protected function getCastType($key) + { + return trim(strtolower($this->casts[$key])); + } + + /** + * Cast an attribute to a native PHP type. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function castAttribute($key, $value) + { + $type = $this->getCastType($key); + switch ($type) + { + case 'int': + case 'integer': + return (int) $value; + case 'real': + case 'float': + case 'double': + return (float) $value; + case 'string': + return (string) $value; + case 'bool': + case 'boolean': + return (bool) $value; + case 'array': + return (array) $value; + case 'object': + return (object) $value; + case 'json': + return json_decode($value, true); + } + return $value; + } + + /** + * Get the value of an attribute using its casting for array conversion. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function castAttributeForArray($key, $value) + { + return $value; + } + /** * Set a given attribute on the model. * @@ -2566,6 +2674,11 @@ public function setAttribute($key, $value) $value = $this->fromDateTime($value); } + if ($this->isJsonCastable($key)) + { + $value = json_encode($value, true); + } + $this->attributes[$key] = $value; } From 2481f8c4956e829e55246a629e9511446c868567 Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Tue, 23 Dec 2014 17:12:46 +0000 Subject: [PATCH 521/577] Graham fixes. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index b6a150b68..b1d28a1c1 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2593,7 +2593,7 @@ protected function isJsonCastable($key) /** * Get the type of cast for a model attribute. * - * @param string $key + * @param string $key * @return string */ protected function getCastType($key) From 54d3683f3c70a67b7abd2e5f3df2bef3bbfc55ca Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 23 Dec 2014 11:36:32 -0600 Subject: [PATCH 522/577] Cleaning up a few things. --- Eloquent/Model.php | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index c45424aba..a0bb1338d 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2424,12 +2424,17 @@ public function attributesToArray() ); } + // Next we will handle any casts that have been setup for this model and cast + // the values to their appropriate type. If the attribute has a mutator we + // will not perform the cast on those attributes to avoid any confusion. foreach ($this->casts as $key => $value) { - if ( ! array_key_exists($key, $attributes)) continue; - if (in_array($key, $mutatedAttributes)) continue; + if ( ! array_key_exists($key, $attributes) || + in_array($key, $mutatedAttributes)) continue; - $attributes[$key] = $this->castAttribute($key, $attributes[$key]); + $attributes[$key] = $this->castAttribute( + $key, $attributes[$key] + ); } // Here we will grab all of the appended, calculated attributes to this model @@ -2692,7 +2697,7 @@ protected function mutateAttributeForArray($key, $value) * Determine whether an attribute should be casted to a native type. * * @param string $key - * @return boolean + * @return bool */ protected function hasCast($key) { @@ -2703,14 +2708,17 @@ protected function hasCast($key) * Determine whether a value is JSON castable for inbound manipulation. * * @param string $key - * @return boolean + * @return bool */ protected function isJsonCastable($key) { if ($this->hasCast($key)) { - return $this->getCastType($key) === 'json'; + $type = $this->getCastType($key); + + return $type === 'json' || $type === 'object'; } + return false; } @@ -2734,8 +2742,7 @@ protected function getCastType($key) */ protected function castAttribute($key, $value) { - $type = $this->getCastType($key); - switch ($type) + switch ($this->getCastType($key)) { case 'int': case 'integer': @@ -2752,23 +2759,12 @@ protected function castAttribute($key, $value) case 'array': return (array) $value; case 'object': - return (object) $value; + return json_decode($value); case 'json': return json_decode($value, true); + default: + return $value; } - return $value; - } - - /** - * Get the value of an attribute using its casting for array conversion. - * - * @param string $key - * @param mixed $value - * @return mixed - */ - protected function castAttributeForArray($key, $value) - { - return $value; } /** @@ -2800,7 +2796,7 @@ public function setAttribute($key, $value) if ($this->isJsonCastable($key)) { - $value = json_encode($value, true); + $value = json_encode($value); } $this->attributes[$key] = $value; From c97be7773a0452f31d1aa7162bacd55ca06bbbf9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 23 Dec 2014 11:58:10 -0600 Subject: [PATCH 523/577] Make array cast work like JSON cast. --- Eloquent/Model.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a0bb1338d..3571b0e21 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -2716,7 +2716,7 @@ protected function isJsonCastable($key) { $type = $this->getCastType($key); - return $type === 'json' || $type === 'object'; + return $type === 'array' || $type === 'json' || $type === 'object'; } return false; @@ -2756,10 +2756,9 @@ protected function castAttribute($key, $value) case 'bool': case 'boolean': return (bool) $value; - case 'array': - return (array) $value; case 'object': return json_decode($value); + case 'array': case 'json': return json_decode($value, true); default: From 9e3e40f5202daec7d3d5711ac4518d1d71718867 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 23 Dec 2014 13:47:47 -0600 Subject: [PATCH 524/577] Some code formatting. --- Eloquent/Model.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index fc15e1c5a..a37d32549 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1478,14 +1478,10 @@ public function push() // us to recurs into all of these nested relations for this model instance. foreach ($this->relations as $models) { - // Models can be a collection of models (hasMany), an individual model (hasOne), - // or null (non-existing hasOne). Convert to an array. - $models = $models instanceof Collection ? $models->all() : array($models); + $models = $models instanceof Collection + ? $models->all() : array($models); - // Filter out any null entries from non-existing relationships. - $models = array_filter($models); - - foreach ($models as $model) + foreach (array_filter($models) as $model) { if ( ! $model->push()) return false; } From a204c074cba6f5d10a2ca597b749c00d4a63a73a Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 26 Dec 2014 01:54:21 +0100 Subject: [PATCH 525/577] Fix docblock and typo --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a37d32549..35b01646f 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1982,7 +1982,7 @@ public function getKey() /** * Get the queueable identity for the entity. * - * @var mixed + * @return mixed */ public function getQueueableId() { From a44f6e24e9a722e9225f19c336acc3c0e2450e80 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Sun, 28 Dec 2014 02:22:57 +1100 Subject: [PATCH 526/577] Don't perform update query after force delete --- Eloquent/SoftDeletingTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/SoftDeletingTrait.php b/Eloquent/SoftDeletingTrait.php index e54523bd2..617c0193c 100644 --- a/Eloquent/SoftDeletingTrait.php +++ b/Eloquent/SoftDeletingTrait.php @@ -42,7 +42,7 @@ protected function performDeleteOnModel() { if ($this->forceDeleting) { - $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete(); + return $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete(); } return $this->runSoftDelete(); From eca15bdb6a9d987aee35bb1f7a65cc37e74a5251 Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Sat, 27 Dec 2014 20:07:41 +0300 Subject: [PATCH 527/577] Removed unused use statements --- Capsule/Manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Capsule/Manager.php b/Capsule/Manager.php index ef72cf75e..aa272faec 100755 --- a/Capsule/Manager.php +++ b/Capsule/Manager.php @@ -1,7 +1,6 @@ Date: Sat, 27 Dec 2014 20:58:21 +0100 Subject: [PATCH 528/577] Remove useless $allowed parameter --- Schema/Blueprint.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 859929732..79f68edce 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -577,10 +577,9 @@ public function enum($column, array $allowed) * Create a new json column on the table. * * @param string $column - * @param array $allowed * @return \Illuminate\Support\Fluent */ - public function json($column, array $allowed) + public function json($column) { return $this->addColumn('json', $column); } From 2c6bf07a9e6aa1ecdf8468a2b606b7a39298718c Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Sat, 27 Dec 2014 20:04:29 +0300 Subject: [PATCH 529/577] DocBlock corrections and typo fixes Signed-off-by: Graham Campbell --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 35b01646f..66d224291 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1354,6 +1354,7 @@ public function getObservableEvents() /** * Set the observable event names. * + * @param array $observables * @return void */ public function setObservableEvents(array $observables) @@ -2002,6 +2003,7 @@ public function getKeyName() /** * Set the primary key for the model. * + * @param string $key * @return void */ public function setKeyName($key) From 24653eff56d5613fad06e66e139a8757ee987cc0 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 27 Dec 2014 21:44:05 +0000 Subject: [PATCH 530/577] Fixed some closure docblocks --- Schema/Blueprint.php | 4 ++-- Schema/Builder.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 859929732..41c0976fc 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -38,8 +38,8 @@ class Blueprint { /** * Create a new schema blueprint. * - * @param string $table - * @param \Closure $callback + * @param string $table + * @param \Closure|null $callback * @return void */ public function __construct($table, Closure $callback = null) diff --git a/Schema/Builder.php b/Schema/Builder.php index 707909b3d..64a129c3b 100755 --- a/Schema/Builder.php +++ b/Schema/Builder.php @@ -172,8 +172,8 @@ protected function build(Blueprint $blueprint) /** * Create a new command set with a Closure. * - * @param string $table - * @param \Closure $callback + * @param string $table + * @param \Closure|null $callback * @return \Illuminate\Database\Schema\Blueprint */ protected function createBlueprint($table, Closure $callback = null) From 79023ccdafecaf593f4ef5e3d12a850c7565ae3b Mon Sep 17 00:00:00 2001 From: Daniel Scholtus Date: Wed, 31 Dec 2014 22:41:21 +0000 Subject: [PATCH 531/577] Fix Eloquent\Builder::where() malfunctioning inside a ScopeInterface Fixes #6116. Closes #6844. Signed-off-by: Graham Campbell --- Eloquent/Model.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 473a6e142..a5fbde5f6 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1760,14 +1760,7 @@ public function freshTimestampString() */ public function newQuery() { - $builder = $this->newEloquentBuilder( - $this->newBaseQueryBuilder() - ); - - // Once we have the query builders, we will set the model instances so the - // builder can easily access any information it may need from the model - // while it is constructing and executing various queries against it. - $builder->setModel($this)->with($this->with); + $builder = $this->newQueryWithoutScopes(); return $this->applyGlobalScopes($builder); } @@ -1792,7 +1785,14 @@ public function newQueryWithoutScope($scope) */ public function newQueryWithoutScopes() { - return $this->removeGlobalScopes($this->newQuery()); + $builder = $this->newEloquentBuilder( + $this->newBaseQueryBuilder() + ); + + // Once we have the query builders, we will set the model instances so the + // builder can easily access any information it may need from the model + // while it is constructing and executing various queries against it. + return $builder->setModel($this)->with($this->with); } /** From 7d95f9b508e18cfc1b98dfdfbe22a670a53cf124 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 2 Jan 2015 14:50:36 +0100 Subject: [PATCH 532/577] Check FQN --- Eloquent/MassAssignmentException.php | 4 +++- Eloquent/ModelNotFoundException.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Eloquent/MassAssignmentException.php b/Eloquent/MassAssignmentException.php index c7fe78e6f..8874c7c5c 100755 --- a/Eloquent/MassAssignmentException.php +++ b/Eloquent/MassAssignmentException.php @@ -1,3 +1,5 @@ Date: Fri, 2 Jan 2015 10:59:58 -0600 Subject: [PATCH 533/577] fix a few formatting things. --- Eloquent/Builder.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index e827a0e28..40bb2af70 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -613,7 +613,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C /** * Add nested relationship count conditions to the query. - * + * * @param string $relations * @param string $operator * @param integer $count @@ -625,14 +625,11 @@ protected function hasNested($relations, $operator = '>=', $count = 1, $boolean { $relations = explode('.', $relations); - // In order to nest "has", we need to add count relation constraints - // on the callback closure. We will do this by simply passing to - // closure its own reference, so it calls itself recursively. + // In order to nest "has", we need to add count relation constraints on the + // callback Closure. We'll do this by simply passing the Closure its own + // reference to itself so it calls itself recursively on each segment. $closure = function ($q) use (&$closure, &$relations, $operator, $count, $boolean, $callback) { - // If the "relation" is specified using dot notation, we will assume - // that developer wants to check simple "has" on the intermediate - // relations and add constraints only on the furthermost query. if (count($relations) > 1) { $q->whereHas(array_shift($relations), $closure); From 482c07c74cb770734c24133a126b656f91d8fcd8 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Fri, 2 Jan 2015 23:04:21 +0600 Subject: [PATCH 534/577] Add a "where date" statement to the query Add a "where date" statement to the query --- Query/Builder.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Query/Builder.php b/Query/Builder.php index b9c34920d..b340e078b 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -869,7 +869,21 @@ public function orWhereNotNull($column) { return $this->whereNotNull($column, 'or'); } - + + /** + * Add a "where date" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereDate($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean); + } + /** * Add a "where day" statement to the query. * From 48f9d48917cc5fedcb5d324e31b0fc41521f0063 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Fri, 2 Jan 2015 23:06:16 +0600 Subject: [PATCH 535/577] Compile a "where date" clause added whereDate ->whereDate("col_name","=","2014-12-07") --- Query/Grammars/Grammar.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 237f8959b..aa551abef 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -376,7 +376,19 @@ protected function whereNotNull(Builder $query, $where) { return $this->wrap($where['column']).' is not null'; } - + + /** + * Compile a "where date" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDate(Builder $query, $where) + { + return $this->dateBasedWhere('date', $query, $where); + } + /** * Compile a "where day" clause. * From 588f21edc8a394fa4f3eb238a8439c319fb23643 Mon Sep 17 00:00:00 2001 From: Pieter De Moor Date: Sat, 3 Jan 2015 18:58:57 +0100 Subject: [PATCH 536/577] Addition of eloquent query functions and tests Addition of findOrNew, firstOrNew, firstOrCreate, updateOrCreate functions to the BelongsToMany, HasOneOrMany and MorphOneOrMany eloquent relationships. --- Eloquent/Relations/BelongsToMany.php | 72 +++++++++++++++++++++++++ Eloquent/Relations/HasOneOrMany.php | 71 ++++++++++++++++++++++++ Eloquent/Relations/MorphOneOrMany.php | 77 +++++++++++++++++++++++++++ 3 files changed, 220 insertions(+) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index f99b404fc..077ca728f 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -512,6 +512,78 @@ public function saveMany(array $models, array $joinings = array()) return $models; } + /** + * Find a related model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = array('*')) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->getRelated()->newInstance(); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance(); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes, array $joining = array(), $touch = true) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes, $joining, $touch); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = array(), array $joining = array(), $touch = true) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($values, $joining, $touch); + } + else + { + $instance->fill($values); + + $instance->save(array('touch' => false)); + } + + return $instance; + } + /** * Create a new instance of the related model. * diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index e6c338c75..53ccc93f9 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -182,6 +182,77 @@ public function saveMany(array $models) return $models; } + /** + * Find a model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = array('*')) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->related->newInstance(); + + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance(); + + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = array()) + { + $instance = $this->firstOrNew($attributes); + + $instance->fill($values); + + $instance->save(); + + return $instance; + } + /** * Create a new instance of the related model. * diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index 4a20351ed..09f42cded 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -93,6 +93,83 @@ public function save(Model $model) return parent::save($model); } + /** + * Find a related model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = array('*')) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->related->newInstance(); + + // When saving a polymorphic relationship, we need to set not only the foreign + // key, but also the foreign key type, which is typically the class name of + // the parent model. This makes the polymorphic item unique in the table. + $this->setForeignAttributesForCreate($instance); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance(); + + // When saving a polymorphic relationship, we need to set not only the foreign + // key, but also the foreign key type, which is typically the class name of + // the parent model. This makes the polymorphic item unique in the table. + $this->setForeignAttributesForCreate($instance); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = array()) + { + $instance = $this->firstOrNew($attributes); + + $instance->fill($values); + + $instance->save(); + + return $instance; + } + /** * Create a new instance of the related model. * From 5c7d338af895df31dabc0dc5667da63a3d252200 Mon Sep 17 00:00:00 2001 From: Pieter De Moor Date: Sat, 3 Jan 2015 19:32:04 +0100 Subject: [PATCH 537/577] update As per GrahamCampbell's comments. --- Eloquent/Relations/BelongsToMany.php | 16 +++++++--------- Eloquent/Relations/HasOneOrMany.php | 4 ++-- Eloquent/Relations/MorphOneOrMany.php | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 077ca728f..6c491b0ec 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -519,7 +519,7 @@ public function saveMany(array $models, array $joinings = array()) * @param array $columns * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model */ - public function findOrNew($id, $columns = array('*')) + public function findOrNew($id, $columns = ['*']) { if (is_null($instance = $this->find($id, $columns))) { @@ -551,7 +551,7 @@ public function firstOrNew(array $attributes) * @param array $attributes * @return \Illuminate\Database\Eloquent\Model */ - public function firstOrCreate(array $attributes, array $joining = array(), $touch = true) + public function firstOrCreate(array $attributes, array $joining = [], $touch = true) { if (is_null($instance = $this->where($attributes)->first())) { @@ -568,18 +568,16 @@ public function firstOrCreate(array $attributes, array $joining = array(), $touc * @param array $values * @return \Illuminate\Database\Eloquent\Model */ - public function updateOrCreate(array $attributes, array $values = array(), array $joining = array(), $touch = true) + public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true) { if (is_null($instance = $this->where($attributes)->first())) { - $instance = $this->create($values, $joining, $touch); + return $this->create($values, $joining, $touch); } - else - { - $instance->fill($values); - $instance->save(array('touch' => false)); - } + $instance->fill($values); + + $instance->save(['touch' => false]); return $instance; } diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 53ccc93f9..2102e49ba 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -189,7 +189,7 @@ public function saveMany(array $models) * @param array $columns * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model */ - public function findOrNew($id, $columns = array('*')) + public function findOrNew($id, $columns = ['*']) { if (is_null($instance = $this->find($id, $columns))) { @@ -242,7 +242,7 @@ public function firstOrCreate(array $attributes) * @param array $values * @return \Illuminate\Database\Eloquent\Model */ - public function updateOrCreate(array $attributes, array $values = array()) + public function updateOrCreate(array $attributes, array $values = []) { $instance = $this->firstOrNew($attributes); diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index 09f42cded..af37109cc 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -100,7 +100,7 @@ public function save(Model $model) * @param array $columns * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model */ - public function findOrNew($id, $columns = array('*')) + public function findOrNew($id, $columns = ['*']) { if (is_null($instance = $this->find($id, $columns))) { @@ -159,7 +159,7 @@ public function firstOrCreate(array $attributes) * @param array $values * @return \Illuminate\Database\Eloquent\Model */ - public function updateOrCreate(array $attributes, array $values = array()) + public function updateOrCreate(array $attributes, array $values = []) { $instance = $this->firstOrNew($attributes); From 7acf4019bed7f6b1cda8e940b742627b11d2b0cd Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 26 Dec 2014 11:56:43 -0500 Subject: [PATCH 538/577] Return collection from query builder --- Eloquent/Builder.php | 27 ++++++++------------------- Eloquent/Model.php | 4 ++-- Query/Builder.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index c2c042206..49b210696 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -150,7 +150,7 @@ public function firstOrFail($columns = array('*')) */ public function get($columns = array('*')) { - $models = $this->getModels($columns); + $models = $this->getModels($columns)->all(); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded, which will solve the @@ -364,30 +364,19 @@ public function onDelete(Closure $callback) * Get the hydrated models without eager loading. * * @param array $columns - * @return \Illuminate\Database\Eloquent\Model[] + * @return \Illuminate\Support\Collection */ public function getModels($columns = array('*')) { - // First, we will simply get the raw results from the query builders which we - // can use to populate an array with Eloquent models. We will pass columns - // that should be selected as well, which are typically just everything. - $results = $this->query->get($columns); - $connection = $this->model->getConnectionName(); - $models = array(); - - // Once we have the results, we can spin through them and instantiate a fresh - // model instance for each records we retrieved from the database. We will - // also set the proper connection name for the model after we create it. - foreach ($results as $result) + // We will first get the raw results from the query builder. We'll then + // transform the raw results into Eloquent models, while also setting + // the proper database connection on every Eloquent model instance. + return $this->query->get($columns)->map(function($result) use ($connection) { - $models[] = $model = $this->model->newFromBuilder($result); - - $model->setConnection($connection); - } - - return $models; + return $this->model->newFromBuilder($result)->setConnection($connection); + }); } /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index f098b66a1..b378e55e1 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -487,11 +487,11 @@ public function newFromBuilder($attributes = array()) /** * Create a collection of models from plain arrays. * - * @param array $items + * @param array|\ArrayAccess $items * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ - public static function hydrate(array $items, $connection = null) + public static function hydrate($items, $connection = null) { $collection = with($instance = new static)->newCollection(); diff --git a/Query/Builder.php b/Query/Builder.php index 8ad93000c..72292ee16 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1287,20 +1287,18 @@ public function pluck($column) * Execute the query and get the first result. * * @param array $columns - * @return mixed|static + * @return mixed */ public function first($columns = array('*')) { - $results = $this->take(1)->get($columns); - - return count($results) > 0 ? reset($results) : null; + return $this->take(1)->get($columns)->first(); } /** * Execute the query as a "select" statement. * * @param array $columns - * @return array|static[] + * @return \Illuminate\Support\Collection */ public function get($columns = array('*')) { @@ -1311,13 +1309,15 @@ public function get($columns = array('*')) * Execute the query as a fresh "select" statement. * * @param array $columns - * @return array|static[] + * @return \Illuminate\Support\Collection */ public function getFresh($columns = array('*')) { if (is_null($this->columns)) $this->columns = $columns; - return $this->processor->processSelect($this, $this->runSelect()); + $results = $this->processor->processSelect($this, $this->runSelect()); + + return new Collection($results); } /** @@ -1462,7 +1462,7 @@ public function lists($column, $key = null) // First we will just get all of the column values for the record result set // then we can associate those values with the column if it was specified // otherwise we can just give these values back without a specific key. - $results = new Collection($this->get($columns)); + $results = $this->get($columns); $values = $results->fetch($columns[0])->all(); @@ -1600,7 +1600,7 @@ public function aggregate($function, $columns = array('*')) $previousColumns = $this->columns; - $results = $this->get($columns); + $results = $this->get($columns)->all(); // Once we have executed the query, we will reset the aggregate property so // that more select queries can be executed against the database without From 833b2c5b4dedf07aca0306df510e88eb40a91076 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 5 Jan 2015 02:09:29 +0100 Subject: [PATCH 539/577] Use FQN for exceptions --- Connection.php | 5 +++-- SqlServerConnection.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Connection.php b/Connection.php index 1aee4a3bc..f58e5510c 100755 --- a/Connection.php +++ b/Connection.php @@ -3,6 +3,7 @@ use PDO; use Closure; use DateTime; +use Exception; use LogicException; use RuntimeException; use Illuminate\Contracts\Events\Dispatcher; @@ -451,7 +452,7 @@ public function transaction(Closure $callback) // If we catch an exception, we will roll back so nothing gets messed // up in the database. Then we'll re-throw the exception so it can // be handled how the developer sees fit for their applications. - catch (\Exception $e) + catch (Exception $e) { $this->rollBack(); @@ -608,7 +609,7 @@ protected function runQueryCallback($query, $bindings, Closure $callback) // If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. - catch (\Exception $e) + catch (Exception $e) { throw new QueryException( $query, $this->prepareBindings($bindings), $e diff --git a/SqlServerConnection.php b/SqlServerConnection.php index 77216c76d..523f7598f 100755 --- a/SqlServerConnection.php +++ b/SqlServerConnection.php @@ -1,6 +1,7 @@ pdo->exec('ROLLBACK TRAN'); From ce0538d025817f7949d4bff3b8a4717862f6e878 Mon Sep 17 00:00:00 2001 From: crynobone Date: Tue, 6 Jan 2015 20:58:23 +0800 Subject: [PATCH 540/577] Remove use of dead `php artisan migrate --path` option, and remove dead `$packagePath`. Signed-off-by: crynobone --- Console/Migrations/MigrateCommand.php | 11 +---------- Console/Migrations/MigrateMakeCommand.php | 13 +------------ MigrationServiceProvider.php | 8 ++------ 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 8c5c779ca..72c48b97e 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -29,24 +29,17 @@ class MigrateCommand extends BaseCommand { */ protected $migrator; - /** - * The path to the packages directory (vendor). - */ - protected $packagePath; - /** * Create a new migration command instance. * * @param \Illuminate\Database\Migrations\Migrator $migrator - * @param string $packagePath * @return void */ - public function __construct(Migrator $migrator, $packagePath) + public function __construct(Migrator $migrator) { parent::__construct(); $this->migrator = $migrator; - $this->packagePath = $packagePath; } /** @@ -115,8 +108,6 @@ protected function getOptions() array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), - array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null), - array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), diff --git a/Console/Migrations/MigrateMakeCommand.php b/Console/Migrations/MigrateMakeCommand.php index 58f4d7d5b..2aafca623 100644 --- a/Console/Migrations/MigrateMakeCommand.php +++ b/Console/Migrations/MigrateMakeCommand.php @@ -28,13 +28,6 @@ class MigrateMakeCommand extends BaseCommand { */ protected $creator; - /** - * The path to the packages directory (vendor). - * - * @var string - */ - protected $packagePath; - /** * @var \Illuminate\Foundation\Composer */ @@ -45,16 +38,14 @@ class MigrateMakeCommand extends BaseCommand { * * @param \Illuminate\Database\Migrations\MigrationCreator $creator * @param \Illuminate\Foundation\Composer $composer - * @param string $packagePath * @return void */ - public function __construct(MigrationCreator $creator, Composer $composer, $packagePath) + public function __construct(MigrationCreator $creator, Composer $composer) { parent::__construct(); $this->creator = $creator; $this->composer = $composer; - $this->packagePath = $packagePath; } /** @@ -122,8 +113,6 @@ protected function getOptions() return array( array('create', null, InputOption::VALUE_OPTIONAL, 'The table to be created.'), - array('path', null, InputOption::VALUE_OPTIONAL, 'Where to store the migration.', null), - array('table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'), ); } diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 247501797..aeca8c52f 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -108,9 +108,7 @@ protected function registerMigrateCommand() { $this->app->singleton('command.migrate', function($app) { - $packagePath = $app['path.base'].'/vendor'; - - return new MigrateCommand($app['migrator'], $packagePath); + return new MigrateCommand($app['migrator']); }); } @@ -190,11 +188,9 @@ protected function registerMakeCommand() // creation of the migrations, and may be extended by these developers. $creator = $app['migration.creator']; - $packagePath = $app['path.base'].'/vendor'; - $composer = $app['composer']; - return new MigrateMakeCommand($creator, $composer, $packagePath); + return new MigrateMakeCommand($creator, $composer); }); } From ff34ad71a4023f5cabecaac79b7ce58027f24678 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 8 Jan 2015 12:03:35 -0600 Subject: [PATCH 541/577] Tweak a few things. --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 923c7fe4e..6a348403f 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -370,7 +370,7 @@ public function getModels($columns = array('*')) { $connection = $this->model->getConnectionName(); - // We will first get the raw results from the query builder. We'll then + // First, We will get the raw results from the query builder. We'll then // transform the raw results into Eloquent models, while also setting // the proper database connection on every Eloquent model instance. return $this->query->get($columns)->map(function($result) use ($connection) From 26ee0c66ec9b448995a114dc7032e295f0035769 Mon Sep 17 00:00:00 2001 From: Mark Beech Date: Thu, 8 Jan 2015 22:45:43 +0000 Subject: [PATCH 542/577] Very small text change in comment --- Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 6a348403f..32c444b2b 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -370,7 +370,7 @@ public function getModels($columns = array('*')) { $connection = $this->model->getConnectionName(); - // First, We will get the raw results from the query builder. We'll then + // First, we will get the raw results from the query builder. We'll then // transform the raw results into Eloquent models, while also setting // the proper database connection on every Eloquent model instance. return $this->query->get($columns)->map(function($result) use ($connection) From 1207f4c07f6916e214e2ef38ecf6a3eb3dd09dff Mon Sep 17 00:00:00 2001 From: jongwoo Yoo Date: Fri, 9 Jan 2015 10:07:27 +0900 Subject: [PATCH 543/577] [4,2] modified model find method so that find method create specific collection modified model find method so that find method create specific collection --- Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index a5fbde5f6..11f6779ec 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -649,10 +649,10 @@ public static function all($columns = array('*')) */ public static function find($id, $columns = array('*')) { - if (is_array($id) && empty($id)) return new Collection; - $instance = new static; + if (is_array($id) && empty($id)) return $instance->newCollection(); + return $instance->newQuery()->find($id, $columns); } From 1934f90b59e6e22f6d84a9fcc24542d3a73e289a Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 9 Jan 2015 10:32:24 -0500 Subject: [PATCH 544/577] Use raw array to load relations --- Eloquent/Relations/BelongsToMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 6c491b0ec..8ea842541 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -153,7 +153,7 @@ public function get($columns = array('*')) $select = $this->getSelectColumns($columns); - $models = $this->query->addSelect($select)->getModels(); + $models = $this->query->addSelect($select)->getModels()->all(); $this->hydratePivotRelation($models); diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 249286e86..139de1ecc 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -205,7 +205,7 @@ public function get($columns = array('*')) // models with the result of those columns as a separate model relation. $select = $this->getSelectColumns($columns); - $models = $this->query->addSelect($select)->getModels(); + $models = $this->query->addSelect($select)->getModels()->all(); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded. This will solve the From 537b1825193b6dbe7d751af5fd7318c501ea9ae0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 9 Jan 2015 15:22:24 -0600 Subject: [PATCH 545/577] Revert "[5.0] Use raw array to load relations" --- Eloquent/Relations/BelongsToMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 8ea842541..6c491b0ec 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -153,7 +153,7 @@ public function get($columns = array('*')) $select = $this->getSelectColumns($columns); - $models = $this->query->addSelect($select)->getModels()->all(); + $models = $this->query->addSelect($select)->getModels(); $this->hydratePivotRelation($models); diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 139de1ecc..249286e86 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -205,7 +205,7 @@ public function get($columns = array('*')) // models with the result of those columns as a separate model relation. $select = $this->getSelectColumns($columns); - $models = $this->query->addSelect($select)->getModels()->all(); + $models = $this->query->addSelect($select)->getModels(); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded. This will solve the From 87370364f3ad95596d89b18840f02896c5469996 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 9 Jan 2015 21:34:55 +0000 Subject: [PATCH 546/577] Revert "Return collection from query builder" This reverts commit 0023d9b6bb2d25195be28227c81729c000ee4b4b. Conflicts: src/Illuminate/Database/Eloquent/Builder.php --- Eloquent/Builder.php | 27 +++++++++++++++++++-------- Eloquent/Model.php | 4 ++-- Query/Builder.php | 18 +++++++++--------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 32c444b2b..2109667e6 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -150,7 +150,7 @@ public function firstOrFail($columns = array('*')) */ public function get($columns = array('*')) { - $models = $this->getModels($columns)->all(); + $models = $this->getModels($columns); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded, which will solve the @@ -364,19 +364,30 @@ public function onDelete(Closure $callback) * Get the hydrated models without eager loading. * * @param array $columns - * @return \Illuminate\Support\Collection + * @return \Illuminate\Database\Eloquent\Model[] */ public function getModels($columns = array('*')) { + // First, we will simply get the raw results from the query builders which we + // can use to populate an array with Eloquent models. We will pass columns + // that should be selected as well, which are typically just everything. + $results = $this->query->get($columns); + $connection = $this->model->getConnectionName(); - // First, we will get the raw results from the query builder. We'll then - // transform the raw results into Eloquent models, while also setting - // the proper database connection on every Eloquent model instance. - return $this->query->get($columns)->map(function($result) use ($connection) + $models = array(); + + // Once we have the results, we can spin through them and instantiate a fresh + // model instance for each records we retrieved from the database. We will + // also set the proper connection name for the model after we create it. + foreach ($results as $result) { - return $this->model->newFromBuilder($result)->setConnection($connection); - }); + $models[] = $model = $this->model->newFromBuilder($result); + + $model->setConnection($connection); + } + + return $models; } /** diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2e7798676..3b608ecd4 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -495,11 +495,11 @@ public function newFromBuilder($attributes = array()) /** * Create a collection of models from plain arrays. * - * @param array|\ArrayAccess $items + * @param array $items * @param string $connection * @return \Illuminate\Database\Eloquent\Collection */ - public static function hydrate($items, $connection = null) + public static function hydrate(array $items, $connection = null) { $collection = with($instance = new static)->newCollection(); diff --git a/Query/Builder.php b/Query/Builder.php index 2d973e37c..c9f2c2f57 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -1330,18 +1330,20 @@ public function pluck($column) * Execute the query and get the first result. * * @param array $columns - * @return mixed + * @return mixed|static */ public function first($columns = array('*')) { - return $this->take(1)->get($columns)->first(); + $results = $this->take(1)->get($columns); + + return count($results) > 0 ? reset($results) : null; } /** * Execute the query as a "select" statement. * * @param array $columns - * @return \Illuminate\Support\Collection + * @return array|static[] */ public function get($columns = array('*')) { @@ -1352,15 +1354,13 @@ public function get($columns = array('*')) * Execute the query as a fresh "select" statement. * * @param array $columns - * @return \Illuminate\Support\Collection + * @return array|static[] */ public function getFresh($columns = array('*')) { if (is_null($this->columns)) $this->columns = $columns; - $results = $this->processor->processSelect($this, $this->runSelect()); - - return new Collection($results); + return $this->processor->processSelect($this, $this->runSelect()); } /** @@ -1505,7 +1505,7 @@ public function lists($column, $key = null) // First we will just get all of the column values for the record result set // then we can associate those values with the column if it was specified // otherwise we can just give these values back without a specific key. - $results = $this->get($columns); + $results = new Collection($this->get($columns)); $values = $results->fetch($columns[0])->all(); @@ -1649,7 +1649,7 @@ public function aggregate($function, $columns = array('*')) $previousColumns = $this->columns; - $results = $this->get($columns)->all(); + $results = $this->get($columns); // Once we have executed the query, we will reset the aggregate property so // that more select queries can be executed against the database without From 22e00e47176508d855667889602afbcef9c20ae7 Mon Sep 17 00:00:00 2001 From: JoostK Date: Mon, 12 Jan 2015 14:27:38 +0100 Subject: [PATCH 547/577] Fix queries with whereIn and empty arrays --- Query/Grammars/Grammar.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index aa551abef..eb3d3e0b8 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -306,6 +306,8 @@ protected function whereNotExists(Builder $query, $where) */ protected function whereIn(Builder $query, $where) { + if (empty($where['values'])) return '0'; + $values = $this->parameterize($where['values']); return $this->wrap($where['column']).' in ('.$values.')'; @@ -320,6 +322,8 @@ protected function whereIn(Builder $query, $where) */ protected function whereNotIn(Builder $query, $where) { + if (empty($where['values'])) return '1'; + $values = $this->parameterize($where['values']); return $this->wrap($where['column']).' not in ('.$values.')'; @@ -376,7 +380,7 @@ protected function whereNotNull(Builder $query, $where) { return $this->wrap($where['column']).' is not null'; } - + /** * Compile a "where date" clause. * @@ -388,7 +392,7 @@ protected function whereDate(Builder $query, $where) { return $this->dateBasedWhere('date', $query, $where); } - + /** * Compile a "where day" clause. * From 1392970390507353708506ea11229fed691c1609 Mon Sep 17 00:00:00 2001 From: JoostK Date: Mon, 12 Jan 2015 17:29:04 +0100 Subject: [PATCH 548/577] Use expression instead of numeric value --- Query/Grammars/Grammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index eb3d3e0b8..bc74bcced 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -306,7 +306,7 @@ protected function whereNotExists(Builder $query, $where) */ protected function whereIn(Builder $query, $where) { - if (empty($where['values'])) return '0'; + if (empty($where['values'])) return '0=1'; $values = $this->parameterize($where['values']); @@ -322,7 +322,7 @@ protected function whereIn(Builder $query, $where) */ protected function whereNotIn(Builder $query, $where) { - if (empty($where['values'])) return '1'; + if (empty($where['values'])) return '1=1'; $values = $this->parameterize($where['values']); From cbf332fd51a40852a8c4d579730262f50a421d7d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 12 Jan 2015 14:31:03 -0600 Subject: [PATCH 549/577] Spacing. --- Query/Grammars/Grammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index bc74bcced..efbd936d8 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -306,7 +306,7 @@ protected function whereNotExists(Builder $query, $where) */ protected function whereIn(Builder $query, $where) { - if (empty($where['values'])) return '0=1'; + if (empty($where['values'])) return '0 = 1'; $values = $this->parameterize($where['values']); @@ -322,7 +322,7 @@ protected function whereIn(Builder $query, $where) */ protected function whereNotIn(Builder $query, $where) { - if (empty($where['values'])) return '1=1'; + if (empty($where['values'])) return '1 = 1'; $values = $this->parameterize($where['values']); From 6e37c45fe7b9ac1681033779d1863bcff4e66cdc Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Wed, 14 Jan 2015 10:45:11 +0100 Subject: [PATCH 550/577] Update some docblocks --- Eloquent/Model.php | 2 ++ Schema/Blueprint.php | 1 + 2 files changed, 3 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 11f6779ec..2cd06c374 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1288,6 +1288,7 @@ public function getObservableEvents() /** * Set the observable event names. * + * @param array $observables * @return void */ public function setObservableEvents(array $observables) @@ -1923,6 +1924,7 @@ public function getKeyName() /** * Set the primary key for the model. * + * @param string $key * @return void */ public function setKeyName($key) diff --git a/Schema/Blueprint.php b/Schema/Blueprint.php index 832b487af..33453abdc 100755 --- a/Schema/Blueprint.php +++ b/Schema/Blueprint.php @@ -661,6 +661,7 @@ public function binary($column) * Add the proper columns for a polymorphic table. * * @param string $name + * @param string|null $indexName * @return void */ public function morphs($name, $indexName = null) From 0110ed3e746a7b4723d6a9ec9845250c3b849f18 Mon Sep 17 00:00:00 2001 From: Can Tecim Date: Thu, 15 Jan 2015 21:58:20 +0200 Subject: [PATCH 551/577] PostgresConnector set app timezone for connection --- Connectors/PostgresConnector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 39b50e37b..264de7ec0 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -36,6 +36,7 @@ public function connect(array $config) $charset = $config['charset']; $connection->prepare("set names '$charset'")->execute(); + $connection->prepare("set timezone='" . \Config::get('app.timezone') . "'")->execute(); // Unlike MySQL, Postgres allows the concept of "schema" and a default schema // may have been specified on the connections. If that is the case we will From a83956d4abcd7ed5d0d3f541878c98397e2af045 Mon Sep 17 00:00:00 2001 From: Can Tecim Date: Thu, 15 Jan 2015 21:58:20 +0200 Subject: [PATCH 552/577] PostgresConnector set app timezone for connection --- Connectors/PostgresConnector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 39b50e37b..8d2ad00c9 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -37,6 +37,10 @@ public function connect(array $config) $connection->prepare("set names '$charset'")->execute(); + $timezone = $config['timezone']; + + $connection->prepare("set timezone='$timezone'")->execute(); + // Unlike MySQL, Postgres allows the concept of "schema" and a default schema // may have been specified on the connections. If that is the case we will // set the default schema search paths to the specified database schema. From 32b21ad5ef77715e105985d80e18f366fb95e87d Mon Sep 17 00:00:00 2001 From: Can Tecim Date: Thu, 15 Jan 2015 22:39:40 +0200 Subject: [PATCH 553/577] PostgresConnector update --- Connectors/PostgresConnector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index a1b6b561e..8d2ad00c9 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -36,7 +36,6 @@ public function connect(array $config) $charset = $config['charset']; $connection->prepare("set names '$charset'")->execute(); - $connection->prepare("set timezone='" . \Config::get('app.timezone') . "'")->execute(); $timezone = $config['timezone']; From 8a61f9606829d8adac1788230bb6ae81c88c8b80 Mon Sep 17 00:00:00 2001 From: Can Tecim Date: Thu, 15 Jan 2015 22:49:01 +0200 Subject: [PATCH 554/577] error checking --- Connectors/PostgresConnector.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 8d2ad00c9..b5a0e5195 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -37,9 +37,11 @@ public function connect(array $config) $connection->prepare("set names '$charset'")->execute(); - $timezone = $config['timezone']; + if(isset($config['timezone'])) { + $timezone = $config['timezone']; - $connection->prepare("set timezone='$timezone'")->execute(); + $connection->prepare("set timezone='$timezone'")->execute(); + } // Unlike MySQL, Postgres allows the concept of "schema" and a default schema // may have been specified on the connections. If that is the case we will From d1339ad85cf5bee34b99f85d17a2a25dc2ac4c28 Mon Sep 17 00:00:00 2001 From: Can Tecim Date: Thu, 15 Jan 2015 23:05:23 +0200 Subject: [PATCH 555/577] cs fix --- Connectors/PostgresConnector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index b5a0e5195..c08f2f51d 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -37,7 +37,8 @@ public function connect(array $config) $connection->prepare("set names '$charset'")->execute(); - if(isset($config['timezone'])) { + if (isset($config['timezone'])) + { $timezone = $config['timezone']; $connection->prepare("set timezone='$timezone'")->execute(); From 84c21ed606d6233b52f1545d71dad10029d4173b Mon Sep 17 00:00:00 2001 From: jongwoo Yoo Date: Mon, 19 Jan 2015 20:10:11 +0900 Subject: [PATCH 556/577] add getMorphType method in MorphTo --- Eloquent/Relations/MorphTo.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ecbd0f845..cd9948f3e 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -194,6 +194,16 @@ public function createModelByType($type) return new $type; } + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + /** * Get the dictionary used by the relationship. * From b5e007e4f6a8a3534fc3e219760acba4b20a1801 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 19 Jan 2015 15:13:42 -0500 Subject: [PATCH 557/577] findOrFail should throw an error when any model is missing --- Eloquent/Builder.php | 13 +++++++++++-- Eloquent/Model.php | 4 +--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 2109667e6..72ec84780 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -105,13 +105,22 @@ public function findMany($id, $columns = array('*')) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|static + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function findOrFail($id, $columns = array('*')) { - if ( ! is_null($model = $this->find($id, $columns))) return $model; + $result = $this->find($id, $columns); + + if (is_array($id)) + { + if (count($result) == count(array_unique($id))) return $result; + } + elseif ( ! is_null($result)) + { + return $result; + } throw (new ModelNotFoundException)->setModel(get_class($this->model)); } diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 3b608ecd4..52ea4d582 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -725,9 +725,7 @@ public static function findOrNew($id, $columns = array('*')) */ public static function findOrFail($id, $columns = array('*')) { - if ( ! is_null($model = static::find($id, $columns))) return $model; - - throw (new ModelNotFoundException)->setModel(get_called_class()); + return static::query()->findOrFail($id, $columns); } /** From 1cddd85712dd9f182a47a77c53eeee5de9f3b5f7 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Mon, 19 Jan 2015 07:37:02 -0500 Subject: [PATCH 558/577] Translate column type correctly when changing This change fixes an issue where un-translated column types were getting passed to DBAL causing a crash. For example, trying to change a `dateTime` column in MySQL would pass 'dateTime' to `Type::getType`, when it is expecting `datetime`. --- Schema/Grammars/Grammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index 2842ca48c..de2bb9d75 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -359,7 +359,7 @@ protected function getDoctrineColumnForChange(Table $table, Fluent $fluent) */ protected function getDoctrineColumnChangeOptions(Fluent $fluent) { - $options = ['type' => Type::getType($fluent['type'])]; + $options = ['type' => Type::getType($this->getType($fluent))]; if (in_array($fluent['type'], ['text', 'mediumText', 'longText'])) { From 7d5df96b9868f6ada511af02d3851d5d4361e683 Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo Date: Tue, 20 Jan 2015 16:37:29 -0500 Subject: [PATCH 559/577] Get migration path from parent --- Console/Migrations/StatusCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php index 5344adaca..c575112f8 100644 --- a/Console/Migrations/StatusCommand.php +++ b/Console/Migrations/StatusCommand.php @@ -76,7 +76,7 @@ public function fire() */ protected function getAllMigrationFiles() { - return $this->migrator->getMigrationFiles($this->laravel['path.database'].'/migrations'); + return $this->migrator->getMigrationFiles($this->getMigrationPath()); } } From fcd5ca40cb00519d60668b9d0413f7bafd40b258 Mon Sep 17 00:00:00 2001 From: Patrick Carlo-Hickman Date: Wed, 21 Jan 2015 00:58:22 +0000 Subject: [PATCH 560/577] Remove getQualifiedParentKeyName() override for relations with no differing functionality. --- Eloquent/Relations/BelongsToMany.php | 10 ---------- Eloquent/Relations/HasManyThrough.php | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index aeb41f6f3..034917d8a 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -1032,16 +1032,6 @@ public function getOtherKey() return $this->table.'.'.$this->otherKey; } - /** - * Get the fully qualified parent key name. - * - * @return string - */ - protected function getQualifiedParentKeyName() - { - return $this->parent->getQualifiedKeyName(); - } - /** * Get the intermediate table for the relationship. * diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index 6ff2c48c8..d0e33a7d8 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -250,16 +250,6 @@ public function paginate($perPage = null, $columns = array('*')) return $pager; } - /** - * Get the key name of the parent model. - * - * @return string - */ - protected function getQualifiedParentKeyName() - { - return $this->parent->getQualifiedKeyName(); - } - /** * Get the key for comparing against the parent key in "has" query. * From 23e3edf0aae089c7943b8e4373895ce9382b556c Mon Sep 17 00:00:00 2001 From: Patrick Carlo-Hickman Date: Wed, 21 Jan 2015 00:59:06 +0000 Subject: [PATCH 561/577] Increase getQualifiedParentKeyName() visibility to public for all relations. --- Eloquent/Relations/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Relations/Relation.php b/Eloquent/Relations/Relation.php index 47165f51d..86d05392d 100755 --- a/Eloquent/Relations/Relation.php +++ b/Eloquent/Relations/Relation.php @@ -213,7 +213,7 @@ public function getParent() * * @return string */ - protected function getQualifiedParentKeyName() + public function getQualifiedParentKeyName() { return $this->parent->getQualifiedKeyName(); } From 7632fd35998105456871fd99da4a3c39a8fc3b08 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 21 Jan 2015 17:34:28 -0500 Subject: [PATCH 562/577] Typos --- Eloquent/Relations/BelongsToMany.php | 2 +- Eloquent/Relations/HasManyThrough.php | 2 +- Eloquent/Relations/HasOneOrMany.php | 2 +- Eloquent/Relations/MorphOneOrMany.php | 2 +- Eloquent/Relations/MorphTo.php | 2 +- Eloquent/Relations/MorphToMany.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Eloquent/Relations/BelongsToMany.php b/Eloquent/Relations/BelongsToMany.php index 865e5802c..0c147c0bf 100755 --- a/Eloquent/Relations/BelongsToMany.php +++ b/Eloquent/Relations/BelongsToMany.php @@ -51,7 +51,7 @@ class BelongsToMany extends Relation { protected $pivotWheres = []; /** - * Create a new has many relationship instance. + * Create a new belongs to many relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent diff --git a/Eloquent/Relations/HasManyThrough.php b/Eloquent/Relations/HasManyThrough.php index e9942331b..a53a24674 100644 --- a/Eloquent/Relations/HasManyThrough.php +++ b/Eloquent/Relations/HasManyThrough.php @@ -29,7 +29,7 @@ class HasManyThrough extends Relation { protected $secondKey; /** - * Create a new has many relationship instance. + * Create a new has many through relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $farParent diff --git a/Eloquent/Relations/HasOneOrMany.php b/Eloquent/Relations/HasOneOrMany.php index 2102e49ba..db6d1fdf6 100755 --- a/Eloquent/Relations/HasOneOrMany.php +++ b/Eloquent/Relations/HasOneOrMany.php @@ -21,7 +21,7 @@ abstract class HasOneOrMany extends Relation { protected $localKey; /** - * Create a new has many relationship instance. + * Create a new has one or many relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent diff --git a/Eloquent/Relations/MorphOneOrMany.php b/Eloquent/Relations/MorphOneOrMany.php index af37109cc..19a98172c 100755 --- a/Eloquent/Relations/MorphOneOrMany.php +++ b/Eloquent/Relations/MorphOneOrMany.php @@ -20,7 +20,7 @@ abstract class MorphOneOrMany extends HasOneOrMany { protected $morphClass; /** - * Create a new has many relationship instance. + * Create a new morph one or many relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index ecbd0f845..fecbb7be2 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -36,7 +36,7 @@ class MorphTo extends BelongsTo { protected $withTrashed = false; /** - * Create a new belongs to relationship instance. + * Create a new morph to relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 2d8d6ac9d..18d970d92 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -29,7 +29,7 @@ class MorphToMany extends BelongsToMany { protected $inverse; /** - * Create a new has many relationship instance. + * Create a new morph to many relationship instance. * * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $parent @@ -38,7 +38,7 @@ class MorphToMany extends BelongsToMany { * @param string $foreignKey * @param string $otherKey * @param string $relationName - * @param bool $inverse + * @param bool $inverse * @return void */ public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false) From 84cb8ef85ed1a8942a963cfbd204be97723ed125 Mon Sep 17 00:00:00 2001 From: Philippe Plantier Date: Thu, 22 Jan 2015 19:23:26 +0100 Subject: [PATCH 563/577] Fixed cloning queries with join bindings being broken Commit aedc6eb0 had the unfortunate side effect of breaking cloned queries which contained "join" bindings: executing one of the clones made all the other clones fail. This should fix the issue. --- Query/Grammars/Grammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index efbd936d8..507503528 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -128,6 +128,8 @@ protected function compileJoins(Builder $query, $joins) { $sql = array(); + $query->setBindings(array(), 'join'); + foreach ($joins as $join) { $table = $this->wrapTable($join->table); @@ -144,8 +146,6 @@ protected function compileJoins(Builder $query, $joins) foreach ($join->bindings as $index => $binding) { - unset($join->bindings[$index]); - $query->addBinding($binding, 'join'); } From bfca455365c2280f5dcf3190918e3d9a286ddac0 Mon Sep 17 00:00:00 2001 From: Philippe Plantier Date: Thu, 22 Jan 2015 21:35:28 +0100 Subject: [PATCH 564/577] Remove the now-useless $index --- Query/Grammars/Grammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Query/Grammars/Grammar.php b/Query/Grammars/Grammar.php index 507503528..6998370bc 100755 --- a/Query/Grammars/Grammar.php +++ b/Query/Grammars/Grammar.php @@ -144,7 +144,7 @@ protected function compileJoins(Builder $query, $joins) $clauses[] = $this->compileJoinConstraint($clause); } - foreach ($join->bindings as $index => $binding) + foreach ($join->bindings as $binding) { $query->addBinding($binding, 'join'); } From b73aa0406fe2e76637e2ca79ae14df1882f7962e Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Thu, 22 Jan 2015 21:37:59 -0500 Subject: [PATCH 565/577] Remove unnecessary findOrFail method --- Eloquent/Model.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 52ea4d582..4ae449abb 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -714,20 +714,6 @@ public static function findOrNew($id, $columns = array('*')) return new static; } - /** - * Find a model by its primary key or throw an exception. - * - * @param mixed $id - * @param array $columns - * @return \Illuminate\Support\Collection|static - * - * @throws \Illuminate\Database\Eloquent\ModelNotFoundException - */ - public static function findOrFail($id, $columns = array('*')) - { - return static::query()->findOrFail($id, $columns); - } - /** * Reload a fresh model instance from the database. * From 73f974d888290b0ad917298370655ccf3ea68c5e Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Sat, 24 Jan 2015 19:55:37 -0500 Subject: [PATCH 566/577] Use Collection@lists in Builder@lists --- Query/Builder.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/Query/Builder.php b/Query/Builder.php index c9f2c2f57..271098faf 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -888,7 +888,7 @@ public function orWhereNotNull($column) { return $this->whereNotNull($column, 'or'); } - + /** * Add a "where date" statement to the query. * @@ -902,7 +902,7 @@ public function whereDate($column, $operator, $value, $boolean = 'and') { return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean); } - + /** * Add a "where day" statement to the query. * @@ -1502,24 +1502,9 @@ public function lists($column, $key = null) { $columns = $this->getListSelect($column, $key); - // First we will just get all of the column values for the record result set - // then we can associate those values with the column if it was specified - // otherwise we can just give these values back without a specific key. $results = new Collection($this->get($columns)); - $values = $results->fetch($columns[0])->all(); - - // If a key was specified and we have results, we will go ahead and combine - // the values with the keys of all of the records so that the values can - // be accessed by the key of the rows instead of simply being numeric. - if ( ! is_null($key) && count($results) > 0) - { - $keys = $results->fetch($key)->all(); - - return array_combine($keys, $values); - } - - return $values; + return $results->lists($columns[0], array_get($columns, 1)); } /** @@ -1536,12 +1521,12 @@ protected function getListSelect($column, $key) // If the selected column contains a "dot", we will remove it so that the list // operation can run normally. Specifying the table is not needed, since we // really want the names of the columns as it is in this resulting array. - if (($dot = strpos($select[0], '.')) !== false) + return array_map(function($column) { - $select[0] = substr($select[0], $dot + 1); - } + $dot = strpos($column, '.'); - return $select; + return $dot === false ? $column : substr($column, $dot + 1); + }, $select); } /** From e5daa98e4d5e6c5f18c5d8ab9721fcd0d69d73f2 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 25 Jan 2015 15:19:59 +0000 Subject: [PATCH 567/577] Massive improvements to composer files --- composer.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index bd6238229..9da2bc308 100755 --- a/composer.json +++ b/composer.json @@ -16,10 +16,6 @@ "illuminate/support": "5.0.*", "nesbot/carbon": "~1.0" }, - "require-dev": { - "illuminate/console": "5.0.*", - "illuminate/filesystem": "5.0.*" - }, "autoload": { "psr-4": { "Illuminate\\Database\\": "" @@ -30,5 +26,10 @@ "dev-master": "5.0-dev" } }, + "suggest": { + "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", + "illuminate/console": "Required to use the database commands (5.0.*).", + "illuminate/filesystem": "Required to use the migrations (5.0.*)." + }, "minimum-stability": "dev" } From c01e382ac8224127f36bd687968952269c61e4b8 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 26 Jan 2015 09:50:29 -0500 Subject: [PATCH 568/577] Make the eloquent builder more fluent --- Eloquent/Builder.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 72ec84780..2d16744d4 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -845,11 +845,13 @@ public function getQuery() * Set the underlying query builder instance. * * @param \Illuminate\Database\Query\Builder $query - * @return void + * @return $this */ public function setQuery($query) { $this->query = $query; + + return $this; } /** @@ -866,11 +868,13 @@ public function getEagerLoads() * Set the relationships being eagerly loaded. * * @param array $eagerLoad - * @return void + * @return $this */ public function setEagerLoads(array $eagerLoad) { $this->eagerLoad = $eagerLoad; + + return $this; } /** From fb86d7ea83444a89ead57a4a4276b44d2471ade5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 26 Jan 2015 09:59:52 -0600 Subject: [PATCH 569/577] Clean up some things. Make time zone set reflect Postgres documentation. --- Connectors/PostgresConnector.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Connectors/PostgresConnector.php b/Connectors/PostgresConnector.php index 9bbef192c..14b0f441e 100755 --- a/Connectors/PostgresConnector.php +++ b/Connectors/PostgresConnector.php @@ -37,11 +37,14 @@ public function connect(array $config) $connection->prepare("set names '$charset'")->execute(); + // Next, we will check to see if a timezone has been specified in this config + // and if it has we will issue a statement to modify the timezone with the + // database. Setting this DB timezone is an optional configuration item. if (isset($config['timezone'])) { $timezone = $config['timezone']; - $connection->prepare("set timezone='$timezone'")->execute(); + $connection->prepare("set time zone '$timezone'")->execute(); } // Unlike MySQL, Postgres allows the concept of "schema" and a default schema From 4e8b0698d33f01454f7b77bb1b6e04603081231f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 26 Jan 2015 10:01:57 -0600 Subject: [PATCH 570/577] Fix comment. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 2cd06c374..ebb60ac56 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1433,7 +1433,7 @@ public function save(array $options = array()) $query = $this->newQueryWithoutScopes(); // If the "saving" event returns false we'll bail out of the save and return - // false, indicating that the save failed. This gives an opportunities to + // false, indicating that the save failed. This provides a chance for any // listeners to cancel save operations if validations fail or whatever. if ($this->fireModelEvent('saving') === false) { From 68b20b895b2779fe9e9c1a1f7fe0ed56dbe244b1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 26 Jan 2015 10:08:23 -0600 Subject: [PATCH 571/577] Fix comment. --- Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index ebb60ac56..20c2c5193 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1410,7 +1410,7 @@ public function push() // To sync all of the relationships to the database, we will simply spin through // the relationships and save each model via this "push" method, which allows - // us to recurs into all of these nested relations for this model instance. + // us to recurse into all of these nested relations for the model instance. foreach ($this->relations as $models) { foreach (Collection::make($models) as $model) From fb337845d505593e5e54348257e9b7f00a62cbb9 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Mon, 26 Jan 2015 20:18:29 -0500 Subject: [PATCH 572/577] Remove dead code This appears to be left-over from before a later refactoring. This function is never called with the `change` parameter, and the code path for changing columns is totally different. --- Schema/Grammars/Grammar.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Schema/Grammars/Grammar.php b/Schema/Grammars/Grammar.php index de2bb9d75..f0c7688b4 100755 --- a/Schema/Grammars/Grammar.php +++ b/Schema/Grammars/Grammar.php @@ -112,14 +112,13 @@ public function compileForeign(Blueprint $blueprint, Fluent $command) * Compile the blueprint's column definitions. * * @param \Illuminate\Database\Schema\Blueprint $blueprint - * @param bool $change * @return array */ - protected function getColumns(Blueprint $blueprint, $change = false) + protected function getColumns(Blueprint $blueprint) { $columns = array(); - foreach ($change ? $blueprint->getChangedColumns() : $blueprint->getAddedColumns() as $column) + foreach ($blueprint->getAddedColumns() as $column) { // Each of the column types have their own compiler functions which are tasked // with turning the column definition into its SQL format for this platform From eabb5ad0db896339f821ef088ca2fd0d6972e137 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 27 Jan 2015 20:51:43 +0000 Subject: [PATCH 573/577] CS fixes --- Console/SeedCommand.php | 2 +- Eloquent/Builder.php | 2 +- Query/Builder.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Console/SeedCommand.php b/Console/SeedCommand.php index 04d3e6d02..cba115b47 100755 --- a/Console/SeedCommand.php +++ b/Console/SeedCommand.php @@ -26,7 +26,7 @@ class SeedCommand extends Command { /** * The connection resolver instance. * - * @var \Illuminate\Database\ConnectionResolverInterface + * @var \Illuminate\Database\ConnectionResolverInterface */ protected $resolver; diff --git a/Eloquent/Builder.php b/Eloquent/Builder.php index 40bb2af70..088b1c541 100755 --- a/Eloquent/Builder.php +++ b/Eloquent/Builder.php @@ -616,7 +616,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C * * @param string $relations * @param string $operator - * @param integer $count + * @param int $count * @param string $boolean * @param \Closure $callback * @return \Illuminate\Database\Eloquent\Builder|static diff --git a/Query/Builder.php b/Query/Builder.php index b340e078b..1fb966532 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -869,7 +869,7 @@ public function orWhereNotNull($column) { return $this->whereNotNull($column, 'or'); } - + /** * Add a "where date" statement to the query. * @@ -883,7 +883,7 @@ public function whereDate($column, $operator, $value, $boolean = 'and') { return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean); } - + /** * Add a "where day" statement to the query. * From 3c0f32844dc6294c444486b487bc6d65bee2060d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 29 Jan 2015 21:57:23 +0000 Subject: [PATCH 574/577] Update versions for 5.1 --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 9da2bc308..a8ff505c2 100755 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=5.4.0", - "illuminate/container": "5.0.*", - "illuminate/contracts": "5.0.*", - "illuminate/support": "5.0.*", + "illuminate/container": "5.1.*", + "illuminate/contracts": "5.1.*", + "illuminate/support": "5.1.*", "nesbot/carbon": "~1.0" }, "autoload": { @@ -23,13 +23,13 @@ }, "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "5.1-dev" } }, "suggest": { "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", - "illuminate/console": "Required to use the database commands (5.0.*).", - "illuminate/filesystem": "Required to use the migrations (5.0.*)." + "illuminate/console": "Required to use the database commands (5.1.*).", + "illuminate/filesystem": "Required to use the migrations (5.1.*)." }, "minimum-stability": "dev" } From f83742f62048e3dd0fe8f2216ed51e98b7d642d8 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Fri, 30 Jan 2015 11:48:08 -0500 Subject: [PATCH 575/577] Touch exits when not using timestamps --- Eloquent/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Eloquent/Model.php b/Eloquent/Model.php index 329975aa6..375e70a35 100755 --- a/Eloquent/Model.php +++ b/Eloquent/Model.php @@ -1720,6 +1720,8 @@ protected function getKeyForSaveQuery() */ public function touch() { + if ( ! $this->timestamps) return false; + $this->updateTimestamps(); return $this->save(); From e51e6c762ff590cdf7f14117aff600b54ff7362c Mon Sep 17 00:00:00 2001 From: darrylcoder Date: Mon, 2 Feb 2015 19:25:39 +0000 Subject: [PATCH 576/577] Added back "--path" for migrations Signed-off-by: Graham Campbell --- Console/Migrations/MigrateCommand.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 72c48b97e..1e809b496 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -58,7 +58,17 @@ public function fire() // a database for real, which is helpful for double checking migrations. $pretend = $this->input->getOption('pretend'); - $path = $this->getMigrationPath(); + // Next, we will check to see if a path option has been defined. If it has + // we will use the path relative to the root of this installation folder + // so that migrations may be run for any path within the applications. + if( ! is_null($path = $this->input->getOption('path'))) + { + $path = $this->laravel['path.base'].'/'.$path; + } + else + { + $path = $this->getMigrationPath(); + } $this->migrator->run($path, $pretend); @@ -106,6 +116,8 @@ protected function getOptions() return array( array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + array('path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed. If not provided, it will use the default migrations path.'), + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), From c571ace791a601bf1bb3f9cf125eb86df00bf3ae Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 2 Feb 2015 19:27:30 +0000 Subject: [PATCH 577/577] Cleanup the migrate command --- Console/Migrations/MigrateCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Console/Migrations/MigrateCommand.php b/Console/Migrations/MigrateCommand.php index 1e809b496..24db86d07 100755 --- a/Console/Migrations/MigrateCommand.php +++ b/Console/Migrations/MigrateCommand.php @@ -61,7 +61,7 @@ public function fire() // Next, we will check to see if a path option has been defined. If it has // we will use the path relative to the root of this installation folder // so that migrations may be run for any path within the applications. - if( ! is_null($path = $this->input->getOption('path'))) + if ( ! is_null($path = $this->input->getOption('path'))) { $path = $this->laravel['path.base'].'/'.$path; } @@ -116,10 +116,10 @@ protected function getOptions() return array( array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), - array('path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed. If not provided, it will use the default migrations path.'), - array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + array('path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'), + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),