-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
don't needed crash if value is empty #2793
base: master
Are you sure you want to change the base?
Conversation
Does this really fix it? The error comes from constructor because of incorrect type. If just change type into Same should be valid for other cells. However I can see value in empty parameter. But instead of cell param how about TD::make('total', 'Total')
->usingComponent(Currency::class, after: '$') // or even without using component
->empty('Account was not set'), If bank account was not set and Plus if the value is |
Sometime who develop frontend/backend have no clue on database. In my case, price column is null. Actually there only 2 choice: |
@xam8re I'm not saying this is good. In fact it is not application-level exception but PHP TypeError because you're passing I don't think your solution would work as it comes after value being passed into class. I'm basically suggesting this solution instead (simplified dummy code) if (is_null($value)) {
return $empty;
}
return new Currency($value); Do not pass |
To be more concrete here is my suggestion Add new property and method into protected $empty = '';
public function empty($empty)
{
$this->empty = $empty;
return $this;
} Change a little - 'value' => $value,
+ 'value' => $value ?? $this->empty, And protected function renderComponent(string $component, $value, array $params = []): ?string
{
+ if (is_null($value)) {
+ return $this->empty;
+ }
[$class, $view] = Blade::componentInfo($component); This way:
Big question for me is what to be considered Or Just change strict |
Yes. Good suggestion. I pr this only because I needed a quick fix. I'm using orchid only from 1 week. I implement your suggestion and re submit it to pr. Thanks |
@xam8re If you need quick fix in a project you may render component itself, e.g // this code part is from my project with exact same problem but for Number component
// Instead I'm using Laravel's Number helper and render everything on my own
TD::make('star_avg_rate', __('Average rate'))
->render(fn (Star $star) => Number::format($star->ranking->points ?? 0, 2)), or use Laravel accessor for attribute to ensure it will return float |
Fixes #
Fix crash if an empty attribute is passed to a component.
Proposed Changes
Added a optional param that represent the empty value.
If empty value is passed, this parameter is used. Default as empty string.