laravellighthouselaravel-lighthouse

How to use custom Laravel rules with arguments with Lighthouse


I have a doubt about the @rules directive. I have created my own Rule in Laravel but I need to pass an argument in the constructor, so I don't know how I can use the @rules directive properly

@rules(apply: ["App\\Rules\\MyCustomRule"])

How can I do something like this? Because the following line doesn't work

@rules(apply: ["new App\\Rules\\MyCustomRule('arg')"])

Thank you in advance!


Solution

  • It is not possible with @rules(apply: [...]) but this can be achieved by using a validator class.