1
I’m a beginner in the Laravel framework and I’m 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 am receiving, but I cannot enter in the database as per image.
Below follows source code.
Controller
public function salvar_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.id as alu_id', 'alunos.matricula as alu_mat', 'alunos.nome as alu_nome',
'diarios.id as dia_id', 'presencas.id as pre_id')
->where('presencas.id', $presenca_id)
->get();
$dados = $request->all();
//dd($dados);
foreach ($dados as $d) {
$registro = new AlunoPresenca();
$registro->presenca_id = $d['presenca_id'];
$registro->presenca = $d['presenca'];
$registro->aluno_id = $d['aluno_id'];
$registro->save();
}
\Session::flash('mensagem',['msg'=>'Registro criado com sucesso!','class'=>'green white-text']);
return redirect()->route('admin.galerias', $imovel->id);
}
View
<form action="{{ 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>