How to troubleshoot the "call to undefined method ParameterBag :: save ()" error?

0

I'm trying to save the data from the protocol checklist, but the following error is occurring at the time of saving:

  

Call to undefined method   Symfony \ Component \ HttpFoundation \ ParameterBag :: save ()   

Thefollowingimageshowstheprotocolchecklistmodelandthesecondimageistherequestvariabledebug.Thisdebugpresentshowthedataisstructured.
Debugofthevariable"request", data coming from the modal checklist protocol. The data marked in yellow is the variables of the checklist and the data marked in red is the id of the array item.

Loopresponsiblefordisplayingprotocolchecklistdata:

@foreach($checklistsProtocolosas$checklistProtocolo)<tr><td><inputtype="text" class="form-control"  id="item" name="item[]" value="{{$checklistProtocolo->item}}"  size ="2"></td>
                                    <td>{{$checklistProtocolo->descricao_item}}</td>   
                                    <input type="hidden"          id="item_descricao_id"  name="item_descricao_id[{{$checklistProtocolo->item}}][]" value="{{$checklistProtocolo->item_descricao_id}}">
                                    <td><input type="checkbox"    id="sim_nao"            name="sim_nao[{{$checklistProtocolo->item}}][]"    {{$checklistProtocolo->sim_nao == null ? '' : 'checked'}}></td>
                                    <td><input type="checkbox"    id="nao_atende"         name="nao_atende[{{$checklistProtocolo->item}}][]" {{$checklistProtocolo->nao_atende == null ? '' : 'checked'}}></td>
                                    <td><input type="date"        id="dt_validade"        name="dt_validade[{{$checklistProtocolo->item}}][]" value="{{$checklistProtocolo->dt_validade}}"></td>
                                    <td><input type="text"        id="pagina_documento"   name="pagina_documento[{{$checklistProtocolo->item}}][]" value="{{$checklistProtocolo->pagina_documento}}" size ="1"></td>
                                    <td><input type="text"        id="observacao"         name="observacao[{{$checklistProtocolo->item}}][]" value="{{$checklistProtocolo->observacao}}" size ="1" style="width: 300px; height: 60px"></td>
                                </tr>

                            @endforeach 



Controller protocol checklist registration method:

 public function cadastroChecklistProtocolo(Request $request)
        {

            dd($request->request);

           //Deletar a tabela de checklist_protocolo
           $checklistsProtocolos = ChecklistProtocolo::where('projeto_id','=', $request->projeto_id)->delete();

           //Recebe os dados do modal Checklist Protocolo
            $checklistProtocolo =  $request->request;

            $checklistProtocolo->save();//está ocorrendo um problema no momento de salvar os dados

        }
    
asked by anonymous 21.11.2018 / 14:12

1 answer

0

To update a template using save , you must first retrieve it, set the attributes you want to update or create, and then call the save method.

In your case you did not retrieve the template, just the request, which is saved in the $checklistProtocolo variable and tried to save it.

Try this:

public function cadastroChecklistProtocolo(Request $request)
{
    // Deletar a tabela de checklist_protocolo
    $checklistsProtocolos = ChecklistProtocolo::where('projeto_id', $request->projeto_id)->delete();

    // Recebe os dados do modal Checklist Protocolo
    $dados = $request->all();

    $checklistsProtocolo = new ChecklistProtocolo;

    $checklistProtocolo->save($dados);
} 

Another way would be to use create

public function cadastroChecklistProtocolo(Request $request)
{
    // Deletar a tabela de checklist_protocolo
    $checklistsProtocolos = ChecklistProtocolo::where('projeto_id', $request->projeto_id)->delete();

    $checklistsProtocolo  = ChecklistProtocolo::create($request->all());
}

Reference

    
21.11.2018 / 14:56