1 | <?php |
||
20 | trait GeneratesUuid |
||
21 | { |
||
22 | /** |
||
23 | * The UUID versions. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $uuidVersions = [ |
||
28 | 'uuid1', |
||
29 | 'uuid3', |
||
30 | 'uuid4', |
||
31 | 'uuid5', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Determine whether an attribute should be cast to a native type. |
||
36 | * |
||
37 | * @param string $key |
||
38 | * @param array|string|null $types |
||
39 | * @return bool |
||
40 | */ |
||
41 | abstract public function hasCast($key, $types = null); |
||
42 | |||
43 | /** |
||
44 | * Boot the trait, adding a creating observer. |
||
45 | * |
||
46 | * When persisting a new model instance, we resolve the UUID field, then set |
||
47 | * a fresh UUID, taking into account if we need to cast to binary or not. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public static function bootGeneratesUuid() |
||
65 | |||
66 | /** |
||
67 | * Resolve a UUID instance for the configured version. |
||
68 | * |
||
69 | * @return \Ramsey\Uuid\Uuid |
||
70 | */ |
||
71 | 6 | public function resolveUuid() |
|
75 | |||
76 | /** |
||
77 | * Resolve the UUID version to use when setting the UUID value. Default to uuid4. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 11 | public function resolveUuidVersion() |
|
89 | |||
90 | /** |
||
91 | * Scope queries to find by UUID. |
||
92 | * |
||
93 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
94 | * @param string $uuid |
||
95 | * |
||
96 | * @return \Illuminate\Database\Eloquent\Builder |
||
97 | */ |
||
98 | 2 | public function scopeWhereUuid($query, $uuid) |
|
106 | |||
107 | /** |
||
108 | * Cast an attribute to a native PHP type. |
||
109 | * |
||
110 | * @param string $key |
||
111 | * @param mixed $value |
||
112 | * @return mixed |
||
113 | */ |
||
114 | 2 | protected function castAttribute($key, $value) |
|
122 | } |
||
123 |
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: