2

I used the laravel validator for credit card information as per instructed here. I can finally let it work but my problem is how can I make its result readable by a user. I am also using Laravel validation like this:

public static function validate()
{
    $val = [
           'card_num' => ['required', 'numeric', new CardNumber],
    ];

    return $val;
}

So, if I clicked the submit button and the field is empty, the result is card numは必須です。 which means card number is required. And if I supply an invalid card number, the result is validation.credit_card.card_length_invalid, how can I make it has the same result as leaving the field empty? I do like this when getting the validation errors in blade php.

<div>
    <label>カード番号</label>
    <input type="text" name="card_num" id="credit-card" value="{{ old('card_num', $user['card_num']) }}" >
</div>
@if ($errors->has('card_num'))
<p class="alert-error">
    {{ $errors->first('card_num') }}
</p>
@endif

UPDATE

I have seen its source file and messages, but I don't want to directly change the vendor files. I have tried adding the custom in validation.php, but it's not working.

'custom' => [
    'validation.card_length_invalid' => '無効なカード長',
    'validation.credit_card' => 'クレジットカード',
],
Eem Jee
  • 1,239
  • 5
  • 30
  • 64

1 Answers1

5

Your array in validation.php is close to correct. Try changing the top-level key to credit_card instead of custom like they have in the source code. I'm not 100% sure, but I don't think this package supports messages in the custom array like the ordinary Laravel rules do. For example:

'credit_card' => [
   'card_length_invalid' => '無効なカード長',
   'credit_card' => 'クレジットカード',
],
D Malan
  • 10,272
  • 3
  • 25
  • 50