jdpowered
2 years ago

Custom 'exists' validator for hashed ids

Posted 2 years ago by jdpowered

What I'm currently trying to achive is to use the exists validation rule.

class MyRequest extends Request
{
    /* [...] */

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'user_id' => 'required|exists:users,id',
        ];
    }
}

However, the user_id I get from the request is a hashed presentation of the actual numeric id (via Hashids). How could I modify the validation rule (or even create a custom one) so it lets me decode the user_id before passing it the the actual exists: rule?

Please sign in or create an account to participate in this conversation.