rjruiz
3 months ago
1073
19
Laravel

Update dynamic table

Posted 3 months ago by rjruiz

Greetings I have problems to update the information that has associated to piece, precisely with its tools, Within my form I have a dynamic table that allows me to add or remove fields dynamically When you want to update the tools associated with the piece I receive the following error:

message: "Trying to get property 'id' of non-object"
exception: "ErrorException"

this is my update method (I think the problem is right here)

        $piece  = Piece::with(['tools.insert'])->findOrFail($id); 

                $addmore = $request->addmore;
                $arrTool = [];

                foreach($addmore as $add)
                {
                    $insert = Insert::create([
                        'code_insert' => $add['code_insert'],
                        'quality'     => $add['quality']
                    ]);  

                    $tools = $insert->tools()->update([
                        'position'   => $add['position'],
                        'code_tool'  => $add['code_tool'],                   
                        'insert_id'  => $insert->id                            
                    ]);                     
                        
                    $arrTool[] = $tools->id;                  
                }              

How could I solve this problem that I am doing wrong?

Please sign in or create an account to participate in this conversation.