Commit 82cab1e3 authored by Jens Segers's avatar Jens Segers

Code style tweak

parent eed876e6
...@@ -51,12 +51,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model { ...@@ -51,12 +51,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/ */
public function getIdAttribute($value) public function getIdAttribute($value)
{ {
if (!$value && array_key_exists('_id', $this->attributes)) { // If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way.
if ( ! $value and array_key_exists('_id', $this->attributes))
{
$value = $this->attributes['_id']; $value = $this->attributes['_id'];
} }
// Return _id as string // Convert MongoId's to string.
if ($value instanceof MongoId) { if ($value instanceof MongoId)
{
return (string) $value; return (string) $value;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment