lundi 17 décembre 2018

Why relation work for inserting but not for getting data?

Product model has relation:

public function ProductImage(){
  return $this->hasMany(\App\ProductImage::class);
}

ProductImage model has back relation:

public function Product()
{
    return $this->belongsTo('App\Product', 'Product_Id', 'Id');
}

When I create product and then bind image to this product, it works fine:

$product = ProductModel::create([
   'Organizations_Id' => Auth::id()
]);

Bind with model ProductImage:

$product->ProductImage()->saveMany($data);

But when I retrieve information I dont get related data from ProductImage:

$products = ProductModel::with("ProductImage")->get();

It gives me empty ProductImage object



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire