diff --git a/src/Casts/Money.php b/src/Casts/Money.php index c5e5389..9d3533f 100644 --- a/src/Casts/Money.php +++ b/src/Casts/Money.php @@ -28,6 +28,7 @@ public function get($model, $key, $value, $attributes) */ public function set($model, $key, $value, $attributes) { + // $currency = data_get($attributes, 'currency'); return Utils::numbersOnly($value); } } diff --git a/src/Expansions/Response.php b/src/Expansions/Response.php index cbf6bc0..25d76e2 100644 --- a/src/Expansions/Response.php +++ b/src/Expansions/Response.php @@ -46,4 +46,34 @@ public function error() ); }; } + + /** + * Formats a error response for the consumable API. + * + * @return Closure + */ + public function apiError() + { + /* + * Returns an error response. + * + * @param array $params + * @param mixed $default + * @return mixed + */ + return function ($error, int $statusCode = 400, ?array $data = []) { + if ($error instanceof MessageBag) { + $error = $error->all(); + } + + /* @var \Illuminate\Support\Facades\Response $this */ + return static::json( + [ + 'error' => $error, + ...$data, + ], + $statusCode + ); + }; + } } diff --git a/src/Support/Find.php b/src/Support/Find.php index 4a6a341..caad3a9 100644 --- a/src/Support/Find.php +++ b/src/Support/Find.php @@ -119,6 +119,7 @@ public static function httpFilterForModel(Model $model, string $namespace = null } else { $internal = Http::isInternalRequest(); + $baseNamespace = $filterNs; if ($internal) { $baseNamespace = $filterNs . 'Internal\\'; } diff --git a/src/Support/Utils.php b/src/Support/Utils.php index baf1d5e..2b0b576 100644 --- a/src/Support/Utils.php +++ b/src/Support/Utils.php @@ -639,7 +639,11 @@ public static function randomNumber($length = 4) */ public static function numbersOnly($string) { - return intval(preg_replace('/[^0-9]/', '', $string)); + // Remove everything except numbers and decimal points + $number = preg_replace('/[^0-9.]/', '', $string); + + // Convert to float and then to integer to handle decimals + return intval(floatval($number) * 100); } /**