在laravel 5.8中,我尝试在用户表状态中传递更新的值 如果我在中传递值“ APPROVED”,则默认情况下列的值为“ PENDING” 使用update.blade.php表单的“状态”列,
DB::table('users')->where('id', $id)->increment('wallet', '1000' );
此代码无需工作。
否则,我使用“状态”列传递值“已拒绝” update.blade.php表单,这次是这段代码
DB::table('users')->where('id', $id)->increment('wallete', '1000' );
应该在用户表“钱包”列中存储值“ 1000”
如何在laravel中使用if,if else,else if来创建此逻辑查询 5.8控制器
public function pan_status_update(Request $request, $id)
{
$pan_status_update = Pan::where('status','=','PENDING')->find($id);
$pan_status_update['status'] = $request->status;
$pan_status_update['manager_id'] = Auth::user()->id;
DB::table('users')->where('id', $id)->increment('wallete', '1000' );
$pan_status_update->save();
return redirect('Pan_request')->with('success','UPDATED SUCCESSFULLY .',);
}
答案 0 :(得分:0)
在这里,尝试此操作,仅当状态设置为拒绝时,它才会更新
public function pan_status_update(Request $request, $id)
{
$pan_status_update = Pan::where('id', $id)
->where('status', 'pending')
->first();
if(!$pan_status_update){
return redirect()->back()->withStatus('Not Found');
}
if($request->status == 'Approved'){
//shouldn't work
}elseif($request->status == 'Rejected'){
DB::table('users')->where('id', $id)->increment('wallet', '1000' );
}else{
return redirect()->back();
}
return redirect('Pan_request')->with('success','UPDATED SUCCESSFULLY .',);