nuna
4 weeks ago
185
6
Laravel

how to fix message: "Undefined index: product_id"

Posted 4 weeks ago by nuna
public function postAssignProduct(Request $request)
    {
            
        $old = apiRequest('tag/showtag', ['id' => $request->id, 'store_id' => $request->store_id]);
    

        $response = apiRequest('tag/post-assign-product', $request->except('_token'));

        $auth = AuthUser()['id'];
        $data2 = $request->except('_token', 'id');
        $data2['product_assigned'] = [];
        foreach ($data2['product_id'] as $value) {
            $data2['product_assigned'][] = getProductName($data2['store_id'], $value);
        };
        $data2['product_assigned'] = implode(", ", $data2['product_assigned']);
        unset($data2['product_id']);
        

        $tag = "TagAssign: ".$old['tag']['name'];
        $auditing = auditCreate('App\TagAssign', $data2, $auth, $tag);
        return $response;
    }

I am getting this error.When try to use empty function is says invalid argument for foreach loop.Please help

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