-
Notifications
You must be signed in to change notification settings - Fork 5
Support parsing custom field values and attach to model during retrieval #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support parsing custom field values and attach to model during retrieval #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+ with comments, thanks!!
*/ | ||
public function loadCustomFieldValues(): void | ||
{ | ||
if (! $this->customFieldValues) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這個attribute拿出來應該是個collection?collection就算是空的做boolean判斷也還會是true,所以可能要用collection的方法去判斷是否為空
|
||
$this->customFieldValues->each(function (CustomFieldValue $customFieldValue) { | ||
$attribute = $customFieldValue->customField->key; | ||
$this->setAttribute($attribute, $customFieldValue->customField->parseValue($customFieldValue->value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 comment
如果改用setRawAttributes
看起來是不經過額外的檢查就set進去,不過這樣就得先跟原來的attributes merge起來再set進去
@@ -14,4 +14,10 @@ public function getValidationRule(): array | |||
$this->key => ['boolean'], | |||
]; | |||
} | |||
|
|||
public function parseValue($value): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 comment
參數也要給mixed type嗎?
@@ -14,4 +15,8 @@ public function getValidationRule(): array | |||
$this->key => ['date'], | |||
]; | |||
} | |||
public function parseValue($value): string | |||
{ | |||
return Carbon::parse($value)->toDateTimeString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 comment
這樣感覺大部分情況轉換前後都是一樣?要考慮回傳Carbona嗎?
``` | ||
|
||
```php | ||
use OnrampLab\CustomFields\Concerns\Customizable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 comment
這段code sample跟上面重複了?
|
||
- **Validation and Error Handling**: The package provides validation capabilities for custom fields, allowing you to validate user input based on the defined rules. It also handles error handling and validation messages in line with Laravel's validation system. | ||
|
||
- **Extensibility**: The package is built with extensibility in mind. You can easily extend and customize its functionality to meet your specific needs by leveraging Laravel's powerful features such as model events, custom validation rules, and more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 comment
這個有點像業務在銷售某個產品哈哈哈 😆
No description provided.