Issues (17)

src/Traits/SetAttribute.php (1 issue)

1
<?php
2
3
namespace Helldar\Roles\Traits;
4
5
use Illuminate\Support\Str;
6
7
/** @mixin \Illuminate\Database\Eloquent\Model */
8
trait SetAttribute
9
{
10 138
    protected function setSlugAttribute($value)
11
    {
12 138
        $value = Str::slug(trim($value), '_');
13
14 138
        $this->setManual('slug', $value);
15 138
    }
16
17 138
    protected function setTitleAttribute($value)
18
    {
19 138
        $this->setManual('title', trim($value));
20 138
    }
21
22 138
    protected function setManual($key, $value)
23
    {
24 138
        $this->attributes[$key] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25 138
    }
26
27 12
    protected function getTitleAttribute($value): string
28
    {
29 12
        return $value ?: Str::title($this->slug);
30
    }
31
}
32