Code cleanup, no functional changes
This commit is contained in:
@@ -16,11 +16,10 @@ trait SingleOrFail
|
||||
Builder::macro('singleOrFail',function () {
|
||||
$result = $this->get();
|
||||
|
||||
if (($x=$result->count()) == 1) {
|
||||
if (($x=$result->count()) === 1)
|
||||
return $result->first();
|
||||
}
|
||||
|
||||
if ($x == 0)
|
||||
if ($x === 0)
|
||||
throw new ModelNotFoundException('Query brings back 0 record(s) called for singleOrFail()');
|
||||
else
|
||||
throw new \Exception(sprintf('Query brings back %d record(s) called for singleOrFail()',$x));
|
||||
@@ -30,9 +29,8 @@ trait SingleOrFail
|
||||
Builder::macro('single',function () {
|
||||
$result = $this->get();
|
||||
|
||||
if ($result->count() == 1) {
|
||||
if ($result->count() === 1)
|
||||
return $result->first();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
});
|
||||
@@ -41,11 +39,10 @@ trait SingleOrFail
|
||||
Builder::macro('singleOrNew',function ($args) {
|
||||
$result = $this->where($args)->get();
|
||||
|
||||
if ($result->count() == 1) {
|
||||
if ($result->count() === 1)
|
||||
return $result->first();
|
||||
}
|
||||
|
||||
return $this->newModelInstance($args);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user