1 | <?php |
||
7 | trait HasSlug |
||
8 | { |
||
9 | /** |
||
10 | * @var \Spatie\Sluggable\SlugOptions |
||
11 | */ |
||
12 | protected $slugOptions; |
||
13 | |||
14 | /** |
||
15 | * Get the options for generating the slug. |
||
16 | */ |
||
17 | abstract public function getSlugOptions() : SlugOptions; |
||
18 | |||
19 | /** |
||
20 | * Boot the trait. |
||
21 | */ |
||
22 | protected static function bootHasSlug() |
||
32 | |||
33 | /** |
||
34 | * Add the slug to the model. |
||
35 | */ |
||
36 | protected function addSlug() |
||
52 | |||
53 | /** |
||
54 | * Generate a non unique slug for this record. |
||
55 | */ |
||
56 | protected function generateNonUniqueSlug() : string |
||
66 | |||
67 | /** |
||
68 | * Determine if a custom slug has been saved. |
||
69 | */ |
||
70 | protected function hasCustomSlugBeenUsed() : bool |
||
76 | |||
77 | /** |
||
78 | * Get the string that should be used as base for the slug. |
||
79 | */ |
||
80 | protected function getSlugSourceString() : string |
||
90 | |||
91 | /** |
||
92 | * Make the given slug unique. |
||
93 | */ |
||
94 | protected function makeSlugUnique(string $slug) : string |
||
105 | |||
106 | /** |
||
107 | * Determine if a record exists with the given slug. |
||
108 | */ |
||
109 | protected function otherRecordExistsWithSlug(string $slug) : bool |
||
115 | |||
116 | /** |
||
117 | * This function will throw an exception when any of the options is missing or invalid. |
||
118 | */ |
||
119 | protected function guardAgainstInvalidSlugOptions() |
||
133 | } |
||
134 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.