Exemplo n.º 1
0
 public function assignExpertCategory()
 {
     $adminId = Session::get('admin_id');
     if (!isset($adminId)) {
         return json_encode(array('message' => 'not logged'));
     }
     $categoryId = Input::get('category');
     $subcategoryId = Input::get('subcategory');
     $category = Category::find($categoryId);
     $subcategory = SubCategory::find($subcategoryId);
     if (isset($category) && isset($subcategory)) {
         $expertId = Session::get('current_expert_id');
         $tempExpertCategory = ExpertCategory::where('category_id', $categoryId)->where('subcategory_id', $subcategoryId)->where('expert_id', $expertId)->get();
         if (isset($tempExpertCategory) && count($tempExpertCategory) > 0) {
             return json_encode(array('message' => 'duplicate'));
         } else {
             $expertCategory = new ExpertCategory();
             $expertCategory->category_id = $categoryId;
             $expertCategory->subcategory_id = $subcategoryId;
             $expertCategory->expert_id = Session::get('expert_id');
             $expertCategory->status = "active";
             $expertCategory->save();
             return json_encode(array('message' => 'done'));
         }
     } else {
         return json_encode(array('message' => 'invalid'));
     }
 }