【问题标题】:Incorrect integer value: '{"id":1,"name":"Main Lab}' for column 'lab_id' at row 1不正确的整数值:第 1 行的列 'lab_id' 的 '{"id":1,"name":"Main Lab}'
【发布时间】:2021-12-11 00:22:09
【问题描述】:

我收到此错误 第 1 行的列“lab_id”的整数值不正确

使用 dd($lab)

它返回 1

但是如果我填写表格并单击 submet 它会返回错误 应该是从挂载函数开始的吧?

我该如何解决这个问题?

有人可以帮忙吗?


    public function submit()
    {
        $this->validate();
        $this->sample->received_at = now();
        $this->sample->lab_id = $this->lab;
        $this->sample->save();
        $this->message = "Sample {$this->samples->sample_id} Registered Successfully";
    }

   

【问题讨论】:

    标签: php laravel livewires


    【解决方案1】:

    不应该是$this->lab->id

    $this->sample->lab_id = $this->lab;
    

    【讨论】:

      【解决方案2】:

      当您设置$this->lab = Lab::find($lab); 时,$this->lab 是一个 Eloquent 模型,而不仅仅是一个 id。您只需将该模型中的 id 分配给您正在创建的示例。

      $this->sample->lab_id = $this->lab->id;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-05-24
        • 2014-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多