add some validation to row edit, better handle setting null cols with empty
This commit is contained in:
@@ -325,8 +325,12 @@ class Changeset
|
||||
foreach ($newVals as $colId => $value) {
|
||||
if (starts_with($colId, '_')) continue; // internals
|
||||
|
||||
if (!isset($origRow->$colId) || $value != $origRow->$colId) {
|
||||
$updateObj[$colId] = $cols[$colId]->cast($value);
|
||||
$col = $cols[$colId];
|
||||
$value = $col->cast($value);
|
||||
$origValue = $col->cast(isset($origRow->$colId) ? $origRow->$colId : null);
|
||||
|
||||
if ($value !== $origValue) {
|
||||
$updateObj[$colId] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Tables;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use JsonSerializable;
|
||||
use MightyPork\Exceptions\SimpleValidationException;
|
||||
use MightyPork\Exceptions\NotApplicableException;
|
||||
use MightyPork\Utils\Utils;
|
||||
|
||||
@@ -172,13 +173,13 @@ class Column implements JsonSerializable, Arrayable
|
||||
if (is_int($value)) return $value;
|
||||
if (is_float($value)) return round($value);
|
||||
if (is_numeric($value)) return intval($value);
|
||||
throw new NotApplicableException("Could not convert value \"$value\" to int!");
|
||||
throw new SimpleValidationException($this->id, "Could not convert value \"$value\" to int!");
|
||||
|
||||
case 'float':
|
||||
if (is_null($value)) return 0;
|
||||
if (is_int($value) || is_float($value)) return (float)$value;
|
||||
if (is_numeric($value)) return floatval($value);
|
||||
throw new NotApplicableException("Could not convert value \"$value\" to float!");
|
||||
throw new SimpleValidationException($this->id, "Could not convert value \"$value\" to float!");
|
||||
|
||||
case 'bool':
|
||||
if (is_null($value)) return false;
|
||||
|
||||
Reference in New Issue
Block a user