I'm trying to get product with his last price (price with last created_at)
I have :
product table:
-id
-name
-created_at
-updated_at
prooduct_prices table:
-id
-product_id
-price
-created_at
-updated_at
in Product model :
public function prices(){
return $this->hasMany('App\Product_price' , 'product_id', 'id');
}
in product_price model:
public function product()
{
return $this->belongsTo('App\Product' , 'product_id');
}
on ProductController.php:
public function GetALlProducts()
{
$products = new Product;
$products = $products->with('prices');
$products = $products->get();
return response()->json($products);
}
I received all products with all their prices and i don't want this
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire