【问题标题】:Difficulties in creating update with Laravel 5.1使用 Laravel 5.1 创建更新的困难
【发布时间】:2017-03-14 20:40:43
【问题描述】:

我正在尝试使用 Laravel 5.1 创建更新,但它显示错误:

我在这个方法中有 2 个更新,我注意到第一个错误已经发生

类型错误:参数 1 传递给 Illuminate\Database\Eloquent\Builder::update() 必须是类型 数组,给定空

我的控制器

 public function update($id)
{


        $dadosForm = $this->request->except('_token');
        $dadosForm = $this->request->offsetUnset('fat_cnpj');
        $dadosForm = $this->request->offsetUnset('vatendimento');
        $dadosForm = $this->request->offsetUnset('integra');
        $dadosForm = $this->request->offsetUnset('material'); 

    $proposta = $this->proposta;

        $proposta->cliente_id = $this->request->get('cliente_id');
        $proposta->contato = $this->request->get('contato');
        $proposta->email = $this->request->get('email');
        $proposta->telefone = $this->request->get('telefone');
        $proposta->fatcnpj = $this->request->get('fatcnpj');
        $proposta->atendimento = $this->request->get('atendimento');
        $proposta->dt_solicitacao = $this->request->get('dt_solicitacao');
        $proposta->dt_vigencia = $this->request->get('dt_vigencia');
        $proposta->vendedor = $this->request->get('vendedor');
        $proposta->coleta = $this->request->get('coleta');
        $proposta->dt_integracao = $this->request->get('dt_integracao');
        $proposta->hr_integracao = $this->request->get('hr_integracao');
        $proposta->frete_material = $this->request->get('frete_material');
        $proposta->status_id = $this->request->get('status_id');  

        $this->proposta->where('id', $id)->update($dadosForm);




        $proposta_id = $id;

        $count = $this->ensaios->max('id');


        for($i=1;$i<=$count;$i++){ //Save Ensaios

        $proposta_ensaios = new PropostaEnsaios();

        $proposta_ensaios->id_proposta = $proposta_id;
        $proposta_ensaios->id_produto = $i;
        $proposta_ensaios->quantidade = $dadosForm['quantidade_'.$i];
        $proposta_ensaios->valor= $dadosForm['valor_'.$i];
        $proposta_ensaios->total = $dadosForm['total_'.$i];

        $proposta_ensaios->where('id', $id)->update($dadosForm);

        } 


    $this->request->session()->flash('alert-success', 'Dados Alterados com Sucesso!');
    return redirect()->route('manage-content');
}

【问题讨论】:

    标签: php laravel oop laravel-5.1 laravel-eloquent


    【解决方案1】:

    您在以下四行中将 $dadosForm 变量设置为 NULL:

        $dadosForm = $this->request->except('_token');
        $dadosForm = $this->request->offsetUnset('fat_cnpj');
        $dadosForm = $this->request->offsetUnset('vatendimento');
        $dadosForm = $this->request->offsetUnset('integra');
        $dadosForm = $this->request->offsetUnset('material');
    

    (作为参考,PHP 将从未指定返回值的函数返回 NULL 值 - 因为 offsetUnset 没有。)我相信您打算做更多类似的事情:

        $this->request->offsetUnset('fat_cnpj');
        $this->request->offsetUnset('vatendimento');
        $this->request->offsetUnset('integra');
        $this->request->offsetUnset('material');
    
        $dadosForm = $this->request->except('_token'); 
    

    【讨论】:

    • 更改错误现在错误在未找到列下方的数组中
    猜你喜欢
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 2023-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多