根据输入值更新状态

时间:2019-07-03 11:41:40

标签: laravel

我正在laravel中创建api,当输入的userid和actvity_id在表中其他状态都匹配为0时,我想用1更新状态列。哪个错误在我的代码中完成。它将状态仅更新为1。

<?php
$user_id=$req->input('user_id');
$actvity_id=$req->input('activity_id');

$getDetailsActivity= DB::table('table_user_create_activity')
                        ->join('table_sub_category','table_user_create_activity.selected_activity_id', '=', 'table_sub_category.sub_category_id')
                        ->join('table_registration','table_registration.user_id','=','table_user_create_activity.user_id')
                        ->select('table_registration.first_name as admin_name','table_registration.profile_pic','sub_category_name','area','activity_type','sub_category_icon','activity_date','start_time','end_time','status')
                        ->where('table_user_create_activity.activity_id',$actvity_id)
                        ->orwhere('table_user_create_activity.user_id',$user_id)
                        ->first();

if($getDetailsActivity!=null){
    DB::update('update table_user_create_activity set status = ? where activity_id = ? and user_id = ?',['1',$actvity_id,$user_id]);
}
else{

    DB::update('update table_user_create_activity set status = ?',['0']);
}

0 个答案:

没有答案