Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandan's avatar
Level 13

Object of class App\Bed could not be converted to int

when i add no of beds then my bed table insert no of times entry so how can do it

here is my code

public function store(Request $request)
    {
        $pgdetails = new Pgdetail(array(
                'room'=>$request->get('room'),
                'bed_type'=>$request->get('bed_type'),
                'no_of_beds'=>$request->get('no_of_beds'),
        ));
        $pgdetails->save();
        $id = $pgdetails->id;
        $beds = $pgdetails->no_of_beds;

        for($no=0;$no<$beds;$no++){
                $beds = New Bed(array(
                    'room_id'=>$id,
                    'bed'=>$no,
                    'status'=>'assign'
                ));
                $beds->save();
        }
        return back();
    }
0 likes
1 reply
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Just saw the error. You are reusing a variable name for two different things

Remove the s

$bed = New Bed(array(
                    'room_id'=>$id,
                    'bed'=>$no,
                    'status'=>'assign'
                ));
                $bed->save();
1 like

Please or to participate in this conversation.