Skip to content

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

Conversation

moon-brillar
Copy link
Contributor

No description provided.

@moon-brillar
Copy link
Contributor Author

Copy link
Contributor

@FishChen1202 FishChen1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+, thanks

@moon-brillar moon-brillar merged commit 34bf42a into main Jun 16, 2023
@moon-brillar moon-brillar deleted the support-parsing-custom-field-values-and-attach-to-model-during-retrieval branch June 16, 2023 02:15
Copy link

@ericHao22 ericHao22 left a 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ action require

這個attribute拿出來應該是個collection?collection就算是空的做boolean判斷也還會是true,所以可能要用collection的方法去判斷是否為空


$this->customFieldValues->each(function (CustomFieldValue $customFieldValue) {
$attribute = $customFieldValue->customField->key;
$this->setAttribute($attribute, $customFieldValue->customField->parseValue($customFieldValue->value));

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

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();

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;

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 comment

這個有點像業務在銷售某個產品哈哈哈 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants