| Conditions | 4 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public function extendRouter() |
||
| 23 | { |
||
| 24 | $router = $this->app->make('router'); |
||
| 25 | |||
| 26 | $router->macro( |
||
| 27 | 'modelWithHashid', |
||
| 28 | function ($key, $class, Closure $callback = null) use ($router) { |
||
| 29 | $router->bind($key, function ($value) use ($router, $class, $callback) { |
||
| 30 | if (is_null($value)) { |
||
| 31 | return; |
||
| 32 | } |
||
| 33 | |||
| 34 | $instance = $router->container->make($class); |
||
| 35 | |||
| 36 | if ($model = $instance->where($instance->getRouteKeyName(), $instance->getKeyForHashid($value))->first()) { |
||
| 37 | return $model; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($callback instanceof Closure) { |
||
| 41 | return call_user_func($callback, $value); |
||
| 42 | } |
||
| 43 | |||
| 44 | throw (new ModelNotFoundException)->setModel($class); |
||
| 45 | }); |
||
| 46 | } |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |