Skip to content

Commit ab23fe8

Browse files
committed
chore(model): [CustomField] add parseValue method
1 parent c9f9175 commit ab23fe8

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

src/Models/BooleanCustomField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ public function getValidationRule(): array
1414
$this->key => ['boolean'],
1515
];
1616
}
17+
18+
public function parseValue($value): bool
19+
{
20+
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
21+
}
22+
1723
}

src/Models/CustomField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ public function getValidationRule(): array
6868
{
6969
return [];
7070
}
71+
72+
public function parseValue($value): mixed
73+
{
74+
return $value;
75+
}
7176
}

src/Models/DateTimeCustomField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OnrampLab\CustomFields\Models;
44

5+
use Carbon\Carbon;
56
use Parental\HasParent;
67

78
class DateTimeCustomField extends CustomField
@@ -14,4 +15,8 @@ public function getValidationRule(): array
1415
$this->key => ['date'],
1516
];
1617
}
18+
public function parseValue($value): string
19+
{
20+
return Carbon::parse($value)->toDateTimeString();
21+
}
1722
}

src/Models/FloatCustomField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ public function getValidationRule(): array
1414
$this->key => ['numeric'],
1515
];
1616
}
17+
18+
public function parseValue($value): float
19+
{
20+
return (float) $value;
21+
}
22+
1723
}

src/Models/IntegerCustomField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ public function getValidationRule(): array
1414
$this->key => ['integer'],
1515
];
1616
}
17+
18+
public function parseValue($value): int
19+
{
20+
return (int) $value;
21+
}
22+
1723
}

src/Models/SelectCustomField.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public function getValidationRule(): array
1616
$this->key => [Rule::in($options)]
1717
];
1818
}
19+
public function parseValue($value): string
20+
{
21+
return $value;
22+
}
1923
}

src/Models/TextCustomField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ public function getValidationRule(): array
1414
$this->key => ['string'],
1515
];
1616
}
17+
18+
public function parseValue($value): string
19+
{
20+
return $value;
21+
}
1722
}

0 commit comments

Comments
 (0)