I have three tables, structure are as follows:
products:
id | name | slug | price
product_attributes:
id | attribute_id | value | qty | product_id
attributes :
id | code | name
Now i'm getting the product and the attributes selected for this particular product using the following relationships but i also want the code and name of the attribute from the third table i.e. attributes:
ProductController.php:
public function show($slug)
{
$product = $this->productRepository->findProductBySlug($slug);
return view('site.pages.product', compact('product'));
}
ProductRepository.php
public function findProductBySlug($slug)
{
$product = Product::with('attributes')->where('slug', $slug)->first();
return $product;
}
Model : Product.php
public function attributes()
{
return $this->hasMany(ProductAttribute::class);
}
getting data on view with following code:
but i also want data from the third table i.e. attributes
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2H9qjQg
via IFTTT
Aucun commentaire:
Enregistrer un commentaire