/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); /** * Register route model bindings */ /** * Instead of throwing a generic 404 if the models are not found * Redirect back with error message * TODO: currently this just redirects back but the session flash does not work. * Keep commented to throw 404, uncomment to redirect back with no message. */ /*$router->model('role', Role::class, function () { throw new GeneralException(trans('exceptions.backend.access.roles.not_found')); }); $router->model('user', User::class, function () { throw new GeneralException(trans('exceptions.backend.access.users.not_found')); });*/ /** * This allows us to use the Route Model Binding with SoftDeletes on * On a model by model basis */ $router->bind('deletedUser', function ($value) { $user = new User(); return User::withTrashed()->where($user->getRouteKeyName(), $value)->first(); }); }
/** * @param $id * @param bool $withRoles * @throws GeneralException * @return mixed */ public function findOrThrowException($id, $withRoles = false) { if ($withRoles) { $user = User::with('roles')->withTrashed()->find($id); } else { $user = User::withTrashed()->find($id); } if (!is_null($user)) { return $user; } throw new GeneralException('That user does not exist.'); }
/** * @param $id * @param bool $withRoles * @throws GeneralException * @return mixed */ public function findOrThrowException($id, $withRoles = false) { if ($withRoles) { $user = User::with('roles')->withTrashed()->find($id); } else { $user = User::withTrashed()->find($id); } if (!is_null($user)) { return $user; } throw new GeneralException(trans('exceptions.backend.access.users.not_found')); }
/** * Define your route model bindings, pattern filters, etc. * * @return void */ public function boot() { /** * Register route model bindings */ /** * This allows us to use the Route Model Binding with SoftDeletes on * On a model by model basis */ $this->bind('deletedUser', function ($value) { $user = new User(); return User::withTrashed()->where($user->getRouteKeyName(), $value)->first(); }); parent::boot(); }