1 | <?php |
||
16 | trait GeneratesUuid |
||
17 | { |
||
18 | /** |
||
19 | * The UUID versions. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $uuidVersions = [ |
||
24 | 'uuid1', |
||
25 | 'uuid3', |
||
26 | 'uuid4', |
||
27 | 'uuid5', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Determine whether an attribute should be cast to a native type. |
||
32 | * |
||
33 | * @param string $key |
||
34 | * @param array|string|null $types |
||
35 | * @return bool |
||
36 | */ |
||
37 | abstract public function hasCast($key, $types = null); |
||
38 | |||
39 | /** |
||
40 | * Boot the trait, adding a creating observer. |
||
41 | * |
||
42 | * When persisting a new model instance, we resolve the UUID field, then set |
||
43 | * a fresh UUID, taking into account if we need to cast to binary or not. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | public static function bootGeneratesUuid() |
||
61 | |||
62 | /** |
||
63 | * Resolve a UUID instance for the configured version. |
||
64 | * |
||
65 | * @return \Ramsey\Uuid\Uuid |
||
66 | */ |
||
67 | 6 | public function resolveUuid() |
|
71 | |||
72 | /** |
||
73 | * Resolve the UUID version to use when setting the UUID value. Default to uuid4. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 11 | public function resolveUuidVersion() |
|
85 | |||
86 | /** |
||
87 | * Scope queries to find by UUID. |
||
88 | * |
||
89 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
90 | * @param string $uuid |
||
91 | * |
||
92 | * @return \Illuminate\Database\Eloquent\Builder |
||
93 | */ |
||
94 | 2 | public function scopeWhereUuid($query, $uuid) |
|
102 | |||
103 | /** |
||
104 | * Cast an attribute to a native PHP type. |
||
105 | * |
||
106 | * @param string $key |
||
107 | * @param mixed $value |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 2 | protected function castAttribute($key, $value) |
|
118 | } |
||
119 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: