Search code examples
phplaravelruleslaravel-nova

How to set a dynamic length in laravel-nova?


I am using Nova in laravel for designing the page,i am writing some rules function which will allows digits:20 .

 Text::make('TrackID','id')->rules('nullable','digits:20' )->sortable()->nullable()->hideFromIndex(),

while updating the data if the numbers are more that it should throw an error like Max 20 digits allowed, now i want to give the length dynamically ,How to do that one

How i am trying

$length=25;

 Text::make('TrackID','id')->rules('nullable',digits:$this->length )->sortable()->nullable()->hideFromIndex(),

Now the error is Max $this->length allowed , please help me to set the length dynamically


Solution

  • one more way is there for doing the same thing

    ->rules('nullable',"digits:.$this->length")
    

    I tested in my local it's working fine ,i hope it will resolve your problem.