0
$message = 'Email already taken';
class EmailUniqueException extends ValidationException
{

public static $defaultTemplates = [

    self::MODE_DEFAULT => [

      self::STANDARD => 'put $message here',
    ],


];
}

I have the code above, in the self::Standard I can easily put my error message as string, but I want to use the variable message because of language specific where app can supply another language text.

1 Answers1

1

I dont know slim well, but you could use global to make your variable accessable in your class:

$message = 'Email already taken';

class EmailUniqueException extends ValidationException
{

    public static $defaultTemplates = [
        global $message;    

        self::MODE_DEFAULT => [
            self::STANDARD => $message,
        ],
    ];
}

Keep in mind tho, that this is ugly as hell and you should rather use some config/translation files to retrieve the information from.

For translations, there is also a package (which is part of laravel) you can use inside your application: https://github.com/illuminate/translation

Manuel Mannhardt
  • 2,191
  • 1
  • 17
  • 23