Skip to content

Support laravel 5.3 #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Jenssegers/Mongodb/MongodbServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function boot()
Model::setConnectionResolver($this->app['db']);

Model::setEventDispatcher($this->app['events']);

if (!defined('SHOULD_RETURN_COLLECTION')) {
$s = explode('.', \Illuminate\Foundation\Application::VERSION);
define('SHOULD_RETURN_COLLECTION', (10 * $s[0] + $s[1]) >= 53);
}
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function find($id, $columns = [])
* Execute the query as a "select" statement.
*
* @param array $columns
* @return array|static[]
* @return array|static[]|Collection
*/
public function get($columns = [])
{
Expand All @@ -157,7 +157,7 @@ public function get($columns = [])
* Execute the query as a fresh "select" statement.
*
* @param array $columns
* @return array|static[]
* @return array|static[]|Collection
*/
public function getFresh($columns = [])
{
Expand Down Expand Up @@ -259,7 +259,7 @@ public function getFresh($columns = [])
$results = iterator_to_array($this->collection->aggregate($pipeline, $options));

// Return results
return $results;
return SHOULD_RETURN_COLLECTION ? new Collection($results) : $results;
}

// Distinct query
Expand All @@ -274,7 +274,7 @@ public function getFresh($columns = [])
$result = $this->collection->distinct($column);
}

return $result;
return SHOULD_RETURN_COLLECTION ? new Collection($result) : $result;
}

// Normal query
Expand Down Expand Up @@ -317,7 +317,8 @@ public function getFresh($columns = [])
$cursor = $this->collection->find($wheres, $options);

// Return results as an array with numeric keys
return iterator_to_array($cursor, false);
$results = iterator_to_array($cursor, false);
return SHOULD_RETURN_COLLECTION ? new Collection($results) : $results;
}
}

Expand Down