我在我的 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)
2 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
将变量名称从更改paid_at
为paidAt
$user->sub_paid_at = $request->paidAt;
但最好你改变格式
$user->sub_paid_at = date("Y-m-d H:i:s",strtotime($request->paidAt));
慕码人8056858
TA贡献1803条经验 获得超6个赞
这解决了我的问题
$user = User::find(Auth::id());
$user->sub_paid_at = date("Y-m-d H:i:s",strtotime($paymentDetails['data']['paidAt']));
$user->role = $paymentDetails['data']['plan_object']['name'];
$user->save();
- 2 回答
- 0 关注
- 134 浏览
添加回答
举报
0/150
提交
取消