0

I have Laravel 8 with Lighthouse package for Graph QL,

I have added @unique directive for "name" attribute, but I am unable to apply this while updating any record, as I want to skip the currently updating record for checking unique,

Below is schema for update

updateRole(id: ID, name: String! @trim @rules(apply : ["unique:roles,name"]), isActive: Int!): Role! @update

When I manually added "id" with rule, it works fine, but I don't know how to make it dynamic rule.

1 Answers1

0

Pass the ID you are receiving from the database to update the data with your Validation rule something like that.

public function update(Request $request, Model $ModelVarible)
{
    $request->validate(["name"=> "unique:tablename,fieldname,{$ModelVarible->id},id"]);
    return redirect('route name');
}
Mudit Gulgulia
  • 1,131
  • 7
  • 21