dpdhnd3577 2015-09-01 07:35
浏览 143

调用未定义的方法whereBetween

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 .

  • 写回答

1条回答 默认 最新

  • dousi0144 2015-09-01 10:38
    关注

    You can't use whereBetween directly eloquent way. Its a query builder method. In case of you want to use it with eloquent it should be called within a Query Scopes.

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计