this is my code:
<?php namespace Models;
class CardBizSetting extends BaseModel {
protected $table = 'mp_member_biz_setting';
public $timestamps = false;
public static $unguarded = true;
public function wechatUsers() {
return $this->hasMany('Models\WcMemberUser', 'bizid');
}
public function exchangesHistories() {
return $this->hasMany('Models\WcMemberCashHistory', 'exchange_bizid');
// ->where('exchange_wechat_id',$this->wc_openid);
}
public function chargeHistories() {
return $this->hasMany('Models\WcMemberCharge', 'charge_bizid');
// ->where('charge_wechatid',$this->wc_openid);
}
// And this function doesn't work--->
public static function updateWechatUserStatus($bizid, $wechatopenid, $status) {
$user = self::find($bizid)->wechatUsers()->where('wc_openid', $wechatopenid)->first();
if ($user) {
$user->update(array('wc_ustatus' => $status));
}
}
}
and this function does not work
Models\CardBizSetting::updateWechatUserStatus(1,'www',1);
So, my question is how to update a hasMany related child model? Thank you very much!
I don't see any error in the method updateWechatUserStatus
. Have you checked if the scope wechatUsers
returns what you expect ? Try to debug your code, and you will see where the problem is coming from.