2
フィールドが追加され、変更することが可能な動的フォームの

laravel 5の入力配列による検証ローカリゼーション?

検証のための形態のコントローラで

<input name="gallery[1][title]"> 
<input name="gallery[1][text]"> 
. 
. 
. 
<input name="gallery[n][title]"> 
<input name="gallery[n][text]"> 

で:ローカリゼーションファイルの

'gallery.*.file' => 'nullable|image', 
'gallery.*.title' => 'nullable|string', 

配列にどれだけの数があるのか​​はわかりません。

'gallery.*.text' => 'text of gallery 1', 
'gallery.*.title' => 'title of gallery 1', 

どうすればいいですか?ギャラリー1

タイトル:

私は結果では、このような何かをしたいです。

。ギャラリーのn

+0

{!! Form::open(['url' => 'actionURL']) !!} {{ csrf_field() }} <input name="gallery[]"> {!! Form::close() !!} 

を形成し、コントローラの検証

を変更する必要がありますバリデータを書き、validaそれとテギャラリー。あなたが書いたバリデーターは深い点検を行うことができます – Cruncher

+0

https://laravel.com/docs/5.0/validation#custom-validation-rules – Cruncher

答えて

0

タイトルはここでこれを行うためのハック方法です。残念ながらlaravelは現在ので、ここで特定のトークンのための一般的なメッセージの代替品を追加サポートしていないことは、あなたが何ができるかです:あなたはまた、すべてでそれらを利用できる持っているサービスプロバイダで代用を追加することができ

$replacer = function ($message, $attribute) { 
    $index = array_get(explode(".",$attribute),1); 
    str_replace(":index",$index,$message); 
    //You may need to do additional replacements here if there's more tokens 
    return $message; 
} 
$this->getValidationFactory()->replacer("nullable", $replacer); 
$this->getValidationFactory()->replacer("string", $replacer); 
$this->getValidationFactory()->replacer("image", $replacer); 
$v = $this->getValidationFactory()->make($request->all(), $rules); 
if ($v->fails()) { 
    $this->throwValidationException($request, $v); //Simulate the $this->validate() behaviour 
} 

:コントローラで

残念ながら、利用可能なルールごとに登録する必要があります。ローカライズファイルで

'gallery.*.text' => 'text of gallery :index', 
'gallery.*.title' => 'title of gallery :index', 
0

はおそらくする必要があります形式でコントローラー

foreach ($request->gallery as $key => $gallery) {   
     $validator = Validator::make(array('gallery => $gallery), 
       array('gallery' => 'required'));   
} 
関連する問題