Skip to content

Commit e1c581a

Browse files
authored
Merge pull request #116 from Muetze42/development
refactor(laravel-eloquent): using methods squish attributes trait
2 parents 47813fb + c2db705 commit e1c581a

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

src/Traits/Models/SquishAttributesTrait.php

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,56 @@ trait SquishAttributesTrait
1818
/**
1919
* The attributes that are mass should squish.
2020
*
21-
* @var string[]
21+
* @retrun string[]
2222
*/
23-
protected array $squishAttributes = [
24-
'city',
25-
'company',
26-
'country',
27-
'department',
28-
'first_name',
29-
'firstname',
30-
'full_name',
31-
'headline',
32-
'house_number',
33-
'industry',
34-
'label',
35-
'last_name',
36-
'lastname',
37-
'name',
38-
'note',
39-
'phone',
40-
'position',
41-
'postal_code',
42-
'salutation',
43-
'state',
44-
'street',
45-
'street_name',
46-
'street_number',
47-
'title',
48-
'zip',
49-
];
23+
protected function squishAttributes(): array
24+
{
25+
return [
26+
'city',
27+
'company',
28+
'country',
29+
'department',
30+
'first_name',
31+
'firstname',
32+
'full_name',
33+
'headline',
34+
'house_number',
35+
'industry',
36+
'label',
37+
'last_name',
38+
'lastname',
39+
'name',
40+
'note',
41+
'phone',
42+
'position',
43+
'postal_code',
44+
'salutation',
45+
'state',
46+
'street',
47+
'street_name',
48+
'street_number',
49+
'title',
50+
'zip',
51+
];
52+
}
5053

5154
/**
5255
* Additional attributes that are mass should squish.
5356
*
54-
* @var string[]
57+
* @retrun string[]
5558
*/
56-
protected array $additionalSquishAttributes = [];
59+
protected function additionalSquishAttributes(): array
60+
{
61+
return [];
62+
}
5763

5864
/**
5965
* Bootstrap the trait.
6066
*/
6167
public static function bootHasSlugTrait(): void
6268
{
6369
static::saving(function (Model $model) {
64-
$attributes = array_merge($this->squishAttributes, $this->additionalSquishAttributes);
70+
$attributes = array_merge($this->squishAttributes(), $this->additionalSquishAttributes());
6571
foreach ($attributes as $attribute) {
6672
if (! empty($model->{$attribute}) && is_string($model->{$attribute})) {
6773
$model->{$attribute} = Str::squish($model->{$attribute});

0 commit comments

Comments
 (0)