Home > database >  Incorrect integer value: '{"id":1,"name":"Main Lab}' for column &
Incorrect integer value: '{"id":1,"name":"Main Lab}' for column &

Time:10-26

I get this error Incorrect integer value for column 'lab_id' at row 1

with dd($lab)

it returns 1

but if I fill the form and click submet it returns the error it should be gettin from mount function?

how can I fix that?

can any one help?


    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";
    }

   

CodePudding user response:

When you set $this->lab = Lab::find($lab);, then $this->lab is an Eloquent model, not just a single id. You need to assign just the id from that model to the sample that you're creating.

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

CodePudding user response:

Shouldn't it be $this->lab->id :

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