我在我的 Laravel 应用程序上成功实现了支付网关
但是我从付款中得到了这个回复
public function handleGatewayCallback()
{
$paymentDetails = Payant::getPaymentData();
dd($paymentDetails);
}
我试图将一些响应保存到用户数据库,但我无法实现这一点。我试过这样做
public function handleGatewayCallback(Request $request)
{
$paymentDetails = Payant::getPaymentData();
// dd($paymentDetails);
$user = User::find(Auth::id());
$user->sub_paid_at = $request->paid_at;
$user->role = $request->planObject['name'];
$user->save();
}
它返回了这个错误
SQLSTATE [23000]:完整性约束违规:1048 列 'sub_paid_at' 不能为空(SQL:更新users集sub_paid_at= ?, users. updated_at= 2019-12-14 07:27:45 where id= 3)
更新
这是我的用户数据库架构
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->enum('role', ['subscriber', 'admin', 'basic', 'couple', 'family'])->default('subscriber');
$table->timestamp('email_verified_at')->nullable();
$table->string('avatar')->nullable();
$table->integer('no_of_logins')->default(0);
$table->date('sub_paid_at')->nullable();
$table->string('session_id')->nullable();
$table->string('password')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
我希望能够从响应中更新用户角色,所以我尝试了这个
$user->role = $request->plan_object['name'];
但它返回错误
SQLSTATE [23000]:完整性约束违规:1048 列“角色”不能为空(SQL:更新users集role= ?,sub_paid_at= 1970-01-01 00:00:00 users,. updated_at= 2019-12-14 08:40:46 其中id= 3)
陪伴而非守候
慕码人8056858