Support the ongoing development of Laravel.io →
posted 9 months ago
Last updated by @nba707 9 months ago.
0

Where are you running the "$this->attributes[]" code?

0

In the model class:

public function setPnAttribute($value) {
$this->attributes['pn'] = strtoupper(trim(substr($value,0,40))); }

0

Replace that with the following and it will work perfectly:

public function setPnAttribute($value)
{
    $this->attributes['pn'] = normalizer_normalize($value, Normalizer::NFKC);
}

About this part of the code: strtoupper(trim(substr($value,0,50))). I recommend you modify the string only after you normalize it so you have a correct and desired output. Otherwise use mbstring instead of the default php functions.

Edit: What i mean by the last part is that the following two examples will always produce correct code:

public function setPnAttribute($value)
{
    $this->attributes['pn'] = strtoupper(trim(substr(normalizer_normalize($value, Normalizer::NFKC))));
}
public function setPnAttribute($value)
{
    $this->attributes['pn'] = normalizer_normalize(mb_strtoupper(trim(mb_substr($value))), Normalizer::NFKC);
}
Last updated 9 months ago.

nba707 liked this reply

1
Solution selected by @nba707

Thank you, I get:

Error Class "App\Normalizer" not found.

I added the \ prefix to Normalizer::NFKC and it works now.

$this->attributes['pn'] = normalizer_normalize($value, \Normalizer::NFKC);

Thank you. Got it working now and moved normalizer into the substr function in the event the bad string has mutti-byte characters,

Last updated 9 months ago.
0

No worries, make sure you read my last edit on the previous comment. Glad you managed it in the end.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Warren nba707 Joined 27 Sep 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.