Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs generation fails for requests that utilise custom values #226

Open
mikeldoka1 opened this issue Sep 19, 2023 · 2 comments · May be fixed by #237
Open

Docs generation fails for requests that utilise custom values #226

mikeldoka1 opened this issue Sep 19, 2023 · 2 comments · May be fixed by #237

Comments

@mikeldoka1
Copy link

I have the following request validation:
'email' => 'required|email|unique:users,email,' . auth()->user()->id
What it does is it allows updating the users email address, while ensuring a unique email, but also if the same email(the users email in the table) is being sent then mark it as fine.

The scramble error is because of the auth()-user()-id part:
Cannot generate request documentation: Attempt to read property "id" on null

@dtufood-kihen
Copy link

I have a similar problem.

⚠️Cannot generate request documentation: Attempt to read property "id" on null

/**
 * Get the validation rules that apply to the request.
 *
 * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
 */
public function rules(): array
{
    return [
        'username' => [
            'required',
            'string',
            'max:50',
            'alpha_num:ascii',
            Rule::unique(Login::class)->ignore($this->route('user')->id, 'user_id'),
        ]
    ];
}

@Alexisgt01
Copy link

You are trying to access a property from a null type, try this:

optional(auth()->user())->id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants