Laravel 收银员取消 returns 调用成员函数取消 null

Laravel Cashier Cancel returns call to member function cancel on null

好吧,这对我来说毫无意义。订阅的方法显然返回 true,但随后取消 returns “ 对成员函数的调用在 null 上取消”。这应该根据 Cashier 的文档工作。有谁知道它为什么会这样做?

public function cancel() {
  $user = auth()->user();
  if( $user->subscribed('CkWraps Subscription') ) {
    $user->subscription('CKWraps Subscription')->cancel();
  }
  return back()->with('status', 'Your subscription has been canceled. We\'re sorry to see you go!');
}

好吧,这很奇怪,但我猜这是某种奇怪的字符编码问题。将订阅名称设置为常量可以修复它。

    define("SUB", 'CkWraps Subscription');
    $user = auth()->user();
    if( $user->subscribed(SUB) ) {
        $user->subscription(SUB)->cancel();
    }