I have 2 table with many to many relationship.
Customer Model >>
public function products()
{
return $this->belongsToMany('Mmtimes\MmtimesLib\Models\Product','customer_product','customer_id','product_id')->withPivot('first_copy','last_copy','to_date');
}
Product Model >>
public function customers()
{
return $this->belongsToMany('Mmtimes\MmtimesLib\Models\Customer', 'customer_product', 'product_id', 'customer_id');
}
I pull data according to "to_date" column >>
public function getCustomerByDate()
{
$todate = date('Y-m-d');
$date = strtotime($todate);
$date = strtotime("+7 day",$date);
$date = date('Y-m-d',$date);
$customers = $this->model->products()->whereBetween('to_date',[$todate,$date])->get();
var_dump($customers);
die();
}
I got the error
Call to undefined method Illuminate\Database\Eloquent\Collection::whereBetween()
Please show me the right way ... Thanks and respect to all .