//Javascript ajax request function update_email_status(id) { var chkbox_id=new Array(); var update_value; $("input[type=checkbox]:checked").each(function(){ chkbox_id.push($(this).closest("tr").attr("id")); }); if(id=="read"){update_value="read";}else if(id=="unread"){update_value="unread"} else if(id=="trash"){update_value="trash"} else if(id=="important"){update_value="important"} else {update_value="draft"}; var response=$.ajax({ type:"post", url:"update/"+chkbox_id, data:{update_value:update_value}, }); response.done(function($response){ email(); $("#"+id).find('span').html($response); }); } //Controller public function update($id) { if(Request::ajax()) { $input=Input::get('fav'); $update_value=Input::get("update_value"); if($input!=null){ $fav=Input::get('fav'); DB::table('email') ->where('Id', $id) ->update(array('favorite' => $fav)); }else{ $chkbox_id=array_map('intval', explode(',', $id)); if($update_value=="read" || $update_value=="unread"){ DB::table('email')->whereIn('Id',$chkbox_id)->update(array('status'=>$update_value)); } else if($update_value=="trash"){ //Counting trash emails $trash_email=$this->role-> where('trash','=','true')->count(); DB::table('email')->whereIn('Id',$chkbox_id)->update(array('trash'=>'true')); return $trash_email;//How to return trash_email to above request } else if($update_value=="important"){ DB::table('email')->whereIn('Id',$chkbox_id)->update(array('important'=>'true')); } else{ $draft_email=$this->role-> where('draft','=','true')->count(); return $draft_email;//How to return draft_email to above request /*DB::table('email')->whereIn('Id',$chkbox_id)->update(array('draft'=>'true')); */ } } } }