I am building a form in Laravel, which receives dynamic input. The user can add a link in the input text, but can choose to add more links as desired. The funcionality for that was developing using jquery. The problem is that when I try to save the form (submit), I get this error message.
ErrorException in helpers.php line 531:
htmlentities() expects parameter 1 to be string, array given (View: C:\Users\jkabbas\Documents\GitProects\rastro\src\resources\views\arquiteturas\novo.blade.php)
This is the code excerpt in the laravel page, which is causing the problem. When I remove the square brackets [] from name="txt-link[]", the error message is gone, but I need to use array because I am dealing with multiple inputs.
<td>
<input type="text" placeholder="Digite o link da arquitetura" class="form-control" id="txt-link" name="txt-link[]" value="{{old('txt-link')}}" style="width: 730px;">
@if($errors->has('txt-link'))
@foreach ($errors->get('txt-link') as $message)
<span class="help-block" style="margin-top:5px; margin-bottom:-5px; color:rgb(170, 56, 56)">
<b>{{ $message }}</b>
</span>
@endforeach
@endif
</td>
Backend code
function store(Request $request) {
$this->validate($request, [
'combo_produto'=>['not_in:0'],
'combo_projeto'=>['not_in:0'],
'txt-link[]'=>['required'],
]);
$save_arquitetura = Arquitetura::create([
'produto_id' =>$request['combo_produto'],
'projeto_id' =>$request['combo_projeto'],
]);
return redirect('/arquiteturas')->with('msg_success', 'Dados salvos com sucesso!');
}