samedi 17 août 2019

How to get data from two related tables in laravel 5

I have 3 tables with foreign keys installed.

customers {customer_id, customer_name}

products {product_id, product_name}

customer_products {id, customer_id, product_id}

My Controller code:

$CustomerProducts = ModelName::where('customer_id', 'somevalue')
->Join('customer_products', 'product_id', '=', 'customer_id')       
->get();

My Model code:

class ModelName extends Model { 
protected $table = 'hd_products';
public $primaryKey = 'id'; }

What is wrong in my code, since I'm getting wrong results. I want to show customer information and its related products.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2H8OUoM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire