Completed
Pull Request — master (#30)
by Sebastian
04:14
created

HasUrl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A bootHasUrl() 0 14 3
1
<?php
2
3
namespace App\Foundation\Models\Traits;
4
5
trait HasUrl
6
{
7
    public static function bootHasUrl()
8
    {
9
        static::saving(function ($model) {
10
11
            if (!in_array('name', $model->translatable ?? [])) {
12
                $model->url = str_slug($model->name);
13
                return;
14
            }
15
16
            foreach ($model->getTranslatedLocales('name') as $locale) {
17
                $model->setTranslation('url', $locale, str_slug($model->getTranslation('name', $locale)));
18
            }
19
        });
20
    }
21
}
22