How to format field names in the output of Laravel validation messages?

Asked

Viewed 46 times

0

I’m using $this->validate() to perform field validation in Laravel, how can I apply an underscore in the name of the fields automatically in the output of all messages referring to validation error?

I’m using Laravel 5.6

1 answer

0

You can use the class OutputFormatterStyle and the methods getFormatter and setStyle

Example:

   use Symfony\Component\Console\Formatter\OutputFormatterStyle;

   // ...

   function OutputHandler($sua_ saida)
   {
        $style = new OutputFormatterStyle('white', array('underscore'));
        $this->command->output->getFormatter()->setStyle('underscored', $style);

       $this->command->output->writeln('<underscored>'.$sua_ saida.'</underscored>');
    }

Place inside a model, and always use Handler to give the output you need to underline:

$class = new ClasseQueRepresentar();
$class->OutputHandler('algo');

Source: https://stillat.com/blog/2016/12/03/custom-command-styles-with-laravel-artisan

Browser other questions tagged

You are not signed in. Login or sign up in order to post.