This repository was archived by the owner on Jul 16, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace LaravelBook \Ardent ;
33
4-
54class Builder extends \Illuminate \Database \Eloquent \Builder {
65
76 /**
@@ -20,14 +19,16 @@ public function first($columns = array('*')) {
2019 return $ this ->maybeFail ('first ' , func_get_args ());
2120 }
2221
22+ /**
23+ * Will test if it should run a normal method or its "orFail" version, and behave accordingly.
24+ * @param string $method called method
25+ * @param array $args given arguments
26+ * @return mixed
27+ */
2328 protected function maybeFail ($ method , $ args ) {
24- $ debug = debug_backtrace (false );
25-
26- if ($ this ->throwOnFind && $ debug [2 ]['function ' ] != "{$ method }OrFail " ) {
27- return call_user_func_array (array ($ this , $ method .'OrFail ' ), $ args );
28- } else {
29- return call_user_func_array ("parent:: $ method " , $ args );
30- }
29+ $ debug = debug_backtrace (false );
30+ $ orFail = $ method .'OrFail ' ;
31+ $ func = ($ this ->throwOnFind && $ debug [2 ]['function ' ] != $ orFail )? array ($ this , $ orFail ) : "parent:: $ method " ;
32+ return call_user_func_array ($ func , $ args );
3133 }
32-
3334}
Original file line number Diff line number Diff line change @@ -9,31 +9,27 @@ class InvalidModelException extends \RuntimeException {
99
1010 /**
1111 * The invalid model.
12- *
1312 * @var \LaravelBook\Ardent\Ardent
1413 */
1514 protected $ model ;
1615
1716 /**
1817 * The message bag instance containing validation error messages
19- *
2018 * @var \Illuminate\Support\MessageBag
2119 */
2220 protected $ errors ;
2321
2422 /**
2523 * Receives the invalid model and sets the {@link model} and {@link errors} properties.
26- *
2724 * @param Ardent $model The troublesome model.
2825 */
29- public function __construct ( Ardent $ model ) {
30- $ this ->model = $ model ;
26+ public function __construct (Ardent $ model ) {
27+ $ this ->model = $ model ;
3128 $ this ->errors = $ model ->errors ();
3229 }
3330
3431 /**
3532 * Returns the model with invalid attributes.
36- *
3733 * @return Ardent
3834 */
3935 public function getModel () {
@@ -42,11 +38,9 @@ public function getModel() {
4238
4339 /**
4440 * Returns directly the message bag instance with the model's errors.
45- *
4641 * @return \Illuminate\Support\MessageBag
4742 */
4843 public function getErrors () {
4944 return $ this ->errors ;
5045 }
51-
5246}
You can’t perform that action at this time.
0 commit comments