公式のドキュメントに書いてありますが、理解できずに困っています。
Laravel5.1のValidate機能を用いて、CSVのデータチェックを行います。
その際に、行数を表示したいのですが、以下のように毎回文字連結を行いたくありません。
$messages = [ 'stock.required' => $row . '行目1列目のデータは必須です', 'stock.numeric' => $row . '行目1列目のデータは数字のみです', 'name.required' => $row . '行目2列目のデータは必須です', 'name.max' => $row . '行目2列目のデータは:maxまでです', ]; $rules = [ 'stock' => 'required|numeric', 'name' => 'required|max:50', ]; $validator = Validator::make($stock_items[$row], $rules, $messages);
できれば、以下のように処理できないかと考えております。
$messages = [ 'stock.required' => ':row行目:col列目のデータは必須です', 'stock.numeric' => ':row行目:col列目のデータは数字のみです', 'name.required' => ':row行目:col列目のデータは必須です', 'name.max' => ':row行目:col列目のデータは:maxまでです', ]; $rules = [ 'stock' => 'required|numeric', 'name' => 'required|max:50', ]; $validator = Validator::make($stock_items[$row], $rules, $messages);
:col(列目)についてはvalidation.phpファイル(root\resources\lang\ja\validation.php)のattributesにて、○列目の○に書き換えてもよいかなと考えております(意味的にも間違ってないと思うので)。
<?php //root\resources\lang\ja\validation.php 'attributes' => [ 'stock' => '1', 'password' => '2', ], <?php //Controller $messages = [ 'stock.required' => ':row行目:attribute列目のデータは必須です', 'stock.numeric' => ':row行目:attribute列目のデータは数字のみです', 'name.required' => ':row行目:attribute列目のデータは必須です', 'name.max' => ':row行目:attribute列目のデータは:maxまでです', ];
どなたか解説ご教示いただけたら幸いです。
よろしくお願いいたします。
あなたの回答
tips
プレビュー