Hi
Im using slim with Eloquent models, trying to join the 2 tables and accessing the data
foreach ($this->cartsession->all() as $product) {
$ids[] = $product['product_id'];
}
// $products = $this->supproduct->find($ids); // This only retrieve data from the 1 table
$products = $this->supproduct->find($ids)->joinProduct();//struggling with this line of code
output join should be
‘supproducts.id’, ‘supproducts.supplierid’ ‘supproducts.stock’ ‘products.images’ ‘products.proddesc’
class Supproduct extends Model {
protected $table = 'supproducts';
protected $fillable = [
'id',
'supplierid',
'stock'
];
public function joinProduct() // join to the product table
{
return $this->belongsTo('App\Models\Product')->select(array('images','proddesc'));
}
class Product extends Model {
protected $table = 'products';
protected $fillable = [
'id',
'images'
'proddesc'
];
public function joinProduct()
{
return $this->hasMany('App\Models\Supproduct');
}