我正在尝试检索Laravel 6中我的订阅表的最后记录ID
以下是我的功能
public function activateApp($id)
{
$app = App::where('appId','=',$id)->firstOrFail();
if($app->payment_option == 'monthly')
{
$renewDate = date('Y-m-d', strtotime(date("Y-m-d", strtotime("+30 day"))));
}
else
{
$renewDate = date('Y-m-d', strtotime(date("Y-m-d", strtotime("+365 day"))));
}
$lastdata = DB::table('subscriptions')->orderBy('id', 'desc')->first();
//dd($lastdata);
//die();
//update app table records
DB::table('apps')
->where('appId', $id)
->update([
'status' => $lastdata,
'renewDate' => $renewDate
]);
return redirect()->route('home');
}
我用过了
$lastdata = DB::table('subscriptions')->orderBy('id', 'desc')->first();
获取ID,但是当它似乎不起作用时(如尝试从该值更新我的应用程序表ststus列时),它没有更新,甚至没有给出错误。即使'dd'也不能正常工作。
(在获取最后一条记录之后,似乎整个功能都停止了工作)
您正在尝试status
使用整个$lastdata
对象进行更新。
我不知道您的数据库架构,但是可能您应该尝试类似的方法
DB::table('apps')
->where('appId', $id)
->update([
'status' => $lastdata->status,
'renewDate' => $renewDate
]);
您还可以subscriptions
再次检查数据库是否包含行,并且该行不为空。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句