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