Skip to content

Commit

Permalink
patches required for base of fixes on api
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jan 10, 2024
1 parent da81fdb commit e96f175
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Casts/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
30 changes: 30 additions & 0 deletions src/Expansions/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
}
}
1 change: 1 addition & 0 deletions src/Support/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public static function httpFilterForModel(Model $model, string $namespace = null
} else {
$internal = Http::isInternalRequest();

$baseNamespace = $filterNs;
if ($internal) {
$baseNamespace = $filterNs . 'Internal\\';
}
Expand Down
6 changes: 5 additions & 1 deletion src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit e96f175

Please sign in to comment.