Conditions | 3 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function authorize() |
||
17 | { |
||
18 | if (auth()->user() instanceof Ministry) { |
||
19 | $routeModel = collect($this->route()->parameters()); |
||
20 | |||
21 | $modelName = $routeModel->keys()->first(); |
||
22 | |||
23 | $binding = collect(app()->getBindings()) |
||
24 | ->filter(function ($binding, $key) use ($modelName) { |
||
25 | return Str::contains($key, '\\'.ucfirst($modelName)) && Str::endsWith($key, 'Service'); |
||
26 | }) |
||
27 | ->keys() |
||
28 | ->first(); |
||
29 | |||
30 | $modelMethod = 'get'.ucwords($modelName); |
||
31 | |||
32 | return $this->user()->can('view', app($binding)->$modelMethod()); |
||
33 | } |
||
34 | |||
35 | return true; |
||
36 | } |
||
50 |