1
私はLaravel 5.3を使用していると私は要求クラスのような内部の最大長さのすべての文字列のためにカスタムメッセージを設定しよう...Laravel 5.3カスタム検証メッセージ配列
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRecordRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
$rules = [
'field_1' => 'string|max:100',
'field_2' => 'string|max:100',
'field_3' => 'string|max:100',
];
return $rules;
}
public function messages()
{
return [
'*.max' => ['string' => 'Insert some value.']
];
}
}
しかし、私がフォームを送信すると、エラーが表示される必要があるときに、 "MessageBag.php行245のErrorException:"とエラーが表示されます。ここで
は、ビューのビュー内にある場合...
<div class="form-group {{ $errors->has('field_1') ? 'has-error' : '' }}">
<label for="">Field 1</label>
{{ Form::text('field_1', $record->field_1, ['class' => 'form-control']) }}
<span class="help-block">{{ $errors->first('field_1') }}</span>
</div>
<div class="form-group {{ $errors->has('field_2') ? 'has-error' : '' }}">
<label for="">Field 2</label>
{{ Form::text('field_2', $record->field_2, ['class' => 'form-control']) }}
<span class="help-block">{{ $errors->first('field_2') }}</span>
</div>
<div class="form-group {{ $errors->has('field_3') ? 'has-error' : '' }}">
<label for="">Field 3</label>
{{ Form::text('field_3', $record->field_1, ['class' => 'form-control']) }}
<span class="help-block">{{ $errors->first('field_3') }}</span>
</div>
は、私は私がいることを表示することができ、どのように、エラーメッセージを宣言するかの瞬間に、要求クラスであるかどうかわからないんだけどカスタムメッセージ?
https://laravel.io/forum/05-13-2014-lost-with-messagebag-and-validation-errorsのようなカスタムエラーメッセージを表示することができます –