Im mit dynamische Formulareingabe Einfügen Array-Daten aber Validierung für Array funktioniert nicht für mich. ohne Eingabe wird in Datenbank als leere Werte gespeichert.Laravel-Validierung für dynamische Formular-Eingabedaten?
In einer Tabellenspalte i wie dieses inerte meine Form Eingang haben, das Hinzufügen dynamischer Formularfeld im mit vueJs:
<tr v-for="row in rows">
<td>{!! Form::text('description[]',null,['class' => 'input-field input-sm','v-model'=>'row.description']) !!}
@if ($errors->has('description'))
<span class="error"><i class="glyphicon glyphicon-warning-sign" data-toggle="tooltip" data-placement="top" title="{{ $errors->first('description') }}"></i></span>@endIf</td>
<td>{!! Form::text('log_time[]',null,['class' => 'input-field input-sm','v-model'=>'row.log_time']) !!}
@if ($errors->has('log_time'))<span class="error"><i class="glyphicon glyphicon-warning-sign" data-toggle="tooltip" data-placement="top" title="{{ $errors->first('log_time') }}"></i></span>@endIf </td>
<td> <a @click="removeRow(row)"><button class="btn btn-danger" type="button" id="dim">
<span class="glyphicon glyphicon-minus"></span></button> </a>
<a @click="addRow"><button class="btn btn-success" type="button" id="dim">
<span class="glyphicon glyphicon-plus"></span></button></a>
</td>
</tr>
Funktion Mein Controller-Speicher:
protected $rules = [
'row.description' => ['required|array'],
'row.log_time' => ['required|array'],
];
public function store(PslCall $call,Request $request)
{
$this->validate($request, $this->rules);
$data = array();
foreach($request->description as $key=>$value){
$data[]=[
'description'=> $value,
'log_time'=> $request->log_time[$key],
'call_id'=>$call->id,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}
PortLog::insert($data);
return Redirect::route('calls.logs.index',$call->id)->with('message','You have successfully submitted');
}
hier können Sie meine dd überprüfen() ohne Eingabe kann ich einfügen :(dafür habe ich die Validierung geben;
array:2 [▼
0 => array:5 [▼
"description" => ""
"log_time" => ""
"call_id" => 2
"created_at" => Carbon {#351 ▶}
"updated_at" => Carbon {#352 ▶}
]
1 => array:5 [▼
"description" => ""
"log_time" => ""
"call_id" => 2
"created_at" => Carbon {#353 ▶}
"updated_at" => Carbon {#354 ▶}
]
]
kann Ihnen versichern, '$ request' enthalten alle Werte Sie validieren möchten? –
@SafoorSafdar Check Frage jetzt – Developer
aussehen, müssen Sie 'row.' von Ihren Validierungsregeln entfernen –