get(); if ($result->count() === 1) return $result->first(); return NULL; }); // When a query should return 1 object, or NULL if it doesnt Builder::macro('singleOrNew',function ($args) { $result = $this->where($args)->get(); if ($result->count() === 1) return $result->first(); return $this->newModelInstance($args); }); } }