0

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

   

Zahraa
  • 67
  • 7

2 Answers2

1

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;
aynber
  • 22,380
  • 8
  • 50
  • 63
1

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

$this->sample->lab_id = $this->lab;
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20