where('type','view'); } public function scopeTypeCart(Query $query){ $query->where('type','cart'); } public function scopeTypeFav(Query $query){ $query->where('type','fav'); } public static function increment($goods,$type){ $goods_id=$goods instanceof Goods ?$goods['id']:$goods; $date=date('Y-m-d'); $has=self::where('goods_id',$goods_id) ->where('date',$date) ->where('type',$type) ->find(); if($has){ $has->setInc('num'); }else{ self::create([ 'goods_id'=>$goods_id, 'date'=>$date, 'type'=>$type, 'num'=>1, ]); } } }