我正在嘗試創建一個API。使用Laravel收銀員(帶條紋)& Laravel護照。Laravel Cashier&Laravel護照 - 無法調用這兩個特徵
public $successStatus = 200;
public function index(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email',
'password' => 'required',
'c_password' => 'required|same:password',
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 401);
}
$input = $request->all();
$input['password'] = bcrypt($input['password']);
$user = User::create($input);
$user = Auth::user();
$success['token'] = $user->createToken('MyApp')->accessToken;
$success['name'] = $user->name;
$success['email'] = $user->email;
$stripeToken = 'tok_visa';
\Stripe\Stripe::setApiKey(env(STRIPE_SECRET));
try
{
$user->newSubscription('monthly')->create($stripeToken, [
'email' => $user->email, 'description' => 'Our First Customer'
]);
return response()->json(['success' => $success], $this->successStatus);
}
catch(Exception $e)
{
return response()->json(['success' => $success], $this->successStatus);
}
"message": "Call to a member function createToken() on null",
"exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
"file": "/Users/Taylor/Documents/Websites/storingcompany/api/app/Http/Controllers/Register.php",
"line": 32,
"trace": [
有什麼我在這裏失蹤?我無法從用戶調用Billable模型特徵。在我的控制器中,它顯示在Authentiable中沒有找到newSubscription而不是Billable。
我的用戶類別:
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Cashier\Billable;
class User extends Authenticatable
{
use Billable;
use HasApiTokens;
use Notifiable;
你得到一個錯誤,什麼是錯誤,如果你做的,什麼是真正發生的事情......你能指望什麼發生,什麼是真正發生 – lagbox
我得到的錯誤如上,我想新的條紋訂閱通過我的用戶模型上的計費特性,但它告訴我它無法在認證下找到 –