dimanche 23 octobre 2016

How to add date with foreign key from Create function Laravel?

I have product table and product_category table.

I add new product as:

$product = Product::create($data);

After try to add category for this added product:

$category = new ProductCategoryItem();
        $category->category_id = $request->parent_id;
        $category->product_id = $product->id;
        $category->save();

But it gives me SQL error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire