1 | <?php |
||||||
2 | |||||||
3 | namespace ApiChef\Obfuscate; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
||||||
6 | use Illuminate\Support\Facades\App; |
||||||
7 | use Jenssegers\Optimus\Optimus; |
||||||
8 | |||||||
9 | trait Obfuscatable |
||||||
10 | { |
||||||
11 | 3 | public function resolveRouteBinding($value, $field = null) |
|||||
12 | { |
||||||
13 | 3 | $value = App::make(Optimus::class)->decode($value); |
|||||
14 | 3 | $model = $this->where($field ?? $this->getRouteKeyName(), $value)->first(); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() The method
getRouteKeyName() does not exist on ApiChef\Obfuscate\Obfuscatable . Did you maybe mean getRouteKey() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
15 | |||||||
16 | 3 | if (! is_null($model)) { |
|||||
17 | 3 | return $model; |
|||||
18 | } |
||||||
19 | |||||||
20 | throw new ModelNotFoundException(); |
||||||
21 | } |
||||||
22 | |||||||
23 | 15 | public function getRouteKey() |
|||||
24 | { |
||||||
25 | 15 | $value = $this->getAttribute($this->getRouteKeyName()); |
|||||
0 ignored issues
–
show
It seems like
getAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
26 | |||||||
27 | 15 | return App::make(Optimus::class)->encode($value); |
|||||
28 | } |
||||||
29 | |||||||
30 | 3 | public function scopeForHash($query, $hash) |
|||||
31 | { |
||||||
32 | 3 | return $query->where('id', App::make(Optimus::class)->decode($hash)); |
|||||
33 | } |
||||||
34 | } |
||||||
35 |