Total Complexity | 7 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | trait Sluggable |
||
9 | { |
||
10 | /** |
||
11 | * Generate a slug on the model on boot |
||
12 | * |
||
13 | * @return void |
||
14 | */ |
||
15 | protected static function bootSluggable(): void |
||
16 | { |
||
17 | static::creating(function (Model $model) { |
||
18 | $model->createUniqueSlug(); |
||
19 | }); |
||
20 | |||
21 | static::updating(function (Model $model) { |
||
22 | $model->createUniqueSlug(); |
||
23 | }); |
||
24 | } |
||
25 | |||
26 | protected function createUniqueSlug(): void |
||
27 | { |
||
28 | $this->slug = $this->generateUniqueSlug(); |
||
|
|||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Generate the unique string slug from the $sluggable property |
||
33 | * in the model |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | protected function generateUniqueSlug(): string |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Assert if the slug exists |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | protected function isSlugExists(string $slug): bool |
||
67 | } |
||
68 | } |