$from] = $this->validate(); $authUser = $this->findUserBySlackIdOrFail($request->userId); $user = $this->findUserBySlackId($from); /** @var Key $key */ $key = $user->keys()->first(); if (!$key) { throw ValidationException::withMessages([ "key" => __("User <@:user> does not have any keys", ["user" => $user->profile->slack_id]) ]); } if ($key->user()->is($authUser)) { throw ValidationException::withMessages([ "key" => __("You can't take the keys from yourself :dzban:"), ]); } $key->user()->associate($authUser); $key->save(); $key->notify(new KeyHasBeenTakenNotification($authUser, $user)); return $this->respondToSlack(__(":white_check_mark: Key no. :key has been taken from user <@:user>", ["key"=>$key->id, "user"=> $user->profile->slack_id])); } protected function getRules(): array { return [ "user" => ["required", new SlackUserExistsRule()], ]; } protected function getMessages(): array { return [ "user.required" => __("You must specified the user you want to take the keys from") ]; } }