Skip to content

Commit a4f7b71

Browse files
committed
Optimize error handling calls
1 parent fc273f8 commit a4f7b71

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Repositories/AbstractRepository.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ abstract class AbstractRepository implements RepositoryContract
103103
*/
104104
public function __construct()
105105
{
106-
$this->errors = new MessageBag;
107-
108106
$this->makeModel();
109107
$this->boot();
110108
}
@@ -666,7 +664,7 @@ protected function applyScope()
666664
*/
667665
public function addError($message)
668666
{
669-
$this->errors->add('message', $message);
667+
$this->getErrors()->add('message', $message);
670668

671669
return null;
672670
}
@@ -678,6 +676,10 @@ public function addError($message)
678676
*/
679677
public function getErrors()
680678
{
679+
if ($this->errors === null) {
680+
$this->errors = new MessageBag;
681+
}
682+
681683
return $this->errors;
682684
}
683685

@@ -690,7 +692,7 @@ public function getErrors()
690692
*/
691693
public function getErrorMessage($default = '')
692694
{
693-
return $this->errors->first('message') ?: $default;
695+
return $this->getErrors()->first('message') ?: $default;
694696

695697
}
696698

0 commit comments

Comments
 (0)