Skip to content

How to access '$this' in rules? #150

Answered by juse-less
francoism90 asked this question in Q&A
Discussion options

You must be logged in to vote

You should be able to access the $id property, by adding array $payload to your rules() method.

I didn't check the documentation right now, but immediately recalled PR #123.

public static function rules(array $payload): array
{
    return [
        'post.name' => ['required', 'string', 'max:40', 'unique:'.Post::class.',name,'.$payload['id']],
    ];
}

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
4 replies
@francoism90
Comment options

@francoism90
Comment options

@alexrififi
Comment options

@juse-less
Comment options

Answer selected by francoism90
Comment options

You must be logged in to vote
4 replies
@rubenvanassche
Comment options

@thewebartisan7
Comment options

@thewebartisan7
Comment options

@rubenvanassche
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants