Saving an Array in the MySQL database - Laravel

1

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>
    
asked by anonymous 25.07.2017 / 16:12

1 answer

0

View

                {!! Form::open(['url'=>'agendas/salvar']) !!}

                <select class="form-control" name="funcionario_id">
                    <option >Selecione</option>
                    @foreach($funcionarios as $funcionario_id)                        
                    <option value="{{$funcionario_id->id}}" >{{$funcionario_id->nome}}</option>                              
                    @endforeach 
                </select>
                <br>
                {!! Form::label('dt_periodo_inicio','Data de Início') !!}     
                <div class="input-group">
                <div class="input-group-addon">
                     <i class="fa fa-calendar"></i>
                </div>              
                {!! Form::input('date','dt_periodo_inicio',null,['class'=>'form-control','autofocos','required' ]) !!}                   
                </div><br>
                {!! Form::label('dt_periodo_fim','Data do Fim') !!}     
                <div class="input-group">
                <div class="input-group-addon">
                     <i class="fa fa-calendar"></i>
                </div>                    
                {!! Form::input('date','dt_periodo_fim',null,['class'=>'form-control','autofocos','required' ]) !!}                   
                </div><br>
                 {{ Form::label(' Suas férias serão : ') }}
                 {{ Form::label('','',['class' => 'control-label qtd_dias_visivel']) }}
                 {!! Form::hidden('qtd_dias','',['class' =>'control-label qtd_dias']) !!}  
                <div>                    
                {!! Form::hidden('usuario_id', Auth::id()) !!} 
                {!! Form::hidden('status', 'true') !!}   
                <br>
                {!! Form::submit('Salvar',['class'=>'btn btn-primary']) !!}                                        
                {!! Form::close() !!}

Controller

Following the template will work, remembering do not forget the route - > Route :: post ('agendas / save', 'AgendasController @ save');

public function save (Request $ request)      {
         $ schedule = new Schedule ();

     $agenda= $agenda ->create($request->all()); // aqui já salva no banco

     \Session::flash('mensagem_sucesso','Funcionário cadastado com sucesso!');         

     return Redirect::to('agendas/novo');
 }
    
10.01.2018 / 21:09