I am a beginner in the Laravel framework and am in need of some help. I need to save an array in the MySQL database, however it is generating the following message.
ErrorException in DiarioController.php line 334: Illegal string offset 'presenca_id
When I debug my values, I see that I'm getting, but I can not insert into the database as the image.
Belowisthesourcecode.
Controller
publicfunctionsalvar_lista_de_presenca(Request$request,$id,$presenca_id){$presencas=DB::table('turma_alunos')->join('turmas','turmas.id','=','turma_alunos.turma_id')->join('alunos','alunos.id','=','turma_alunos.aluno_id')->join('tur_prof_discs','tur_prof_discs.turma_id','=','turmas.id')->join('diarios','diarios.tur_prof_discs_id','=','tur_prof_discs.id')->join('presencas','presencas.diario_id','=','diarios.id')->select('turma_alunos.*','alunos.idasalu_id','alunos.matriculaasalu_mat','alunos.nomeasalu_nome','diarios.idasdia_id','presencas.idaspre_id')->where('presencas.id',$presenca_id)->get();$dados=$request->all();//dd($dados);foreach($dadosas$d){$registro=newAlunoPresenca();$registro->presenca_id=$d['presenca_id'];$registro->presenca=$d['presenca'];$registro->aluno_id=$d['aluno_id'];$registro->save();}\Session::flash('mensagem',['msg'=>'Registrocriadocomsucesso!','class'=>'greenwhite-text']);returnredirect()->route('admin.galerias',$imovel->id);}
View
<formaction="{{ route('admin.diario_online.salvar_lista_de_presenca', [$tpd, $diario]) }}" method="post">
{{ csrf_field() }}
<button class="btn waves-effect waves-light blue">
Adicionar
<i class="material-icons right">add</i>
</button>
<div class="row col s12 m12">
<table class="bordered highlight responsive-table centered">
<thead>
<tr>
<th></th>
<th>Matricula</th>
<th>Aluno</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($presencas as $presenca)
<tr>
<td>
<div class="input-field">
<input type="hidden" name="presenca_id[]" value="{{ $presenca->pre_id }}">
</div>
</td>
<td>{{ $presenca->alu_mat }}</td>
<td>{{ $presenca->alu_nome }}</td>
<td>
<!-- Switch -->
<div class="switch">
<label>
Ausente
<input type="checkbox" name="presenca[]" checked="checked" value="1">
<span class="lever"></span>
Presente
</label>
</div>
</td>
<td>
<div class="input-field">
<input type="hidden" name="aluno_id[]" value="{{ $presenca->alu_id }}">
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</form>