emsifa / evo

Evolve your Laravel code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot assign except value for Unique rule

emsifa opened this issue · comments

Unique rule attribute cannot ignore ID like Laravel code below:

Rule::unique('users')->ignore(request("id")),

We can't do that because attribute doesn't allowed to call function like following code below:

#[Unique("users", "id", ignore: request("id"))]

But in most cases, the ignore value is come from request data (not the controller logic), so I think we can add parameter string $ignore to make the same functionality like following code below:

#[Unique("users", "id", ignore: "param:id")]

In example above, we can change param with query, header, cookie, or body.

The limitation with this approach is, the Dto will be less reusable since we cannot change the source of the input to ignore. For example if we specify ignore:"param:id", we cannot use the Dto for route that doesn't have id parameter.