/** * Display a listing of the resource. * GET /subcategories * * @return Response */ public function index() { $subCategory = new SubCategory(); $subCategory->name = Request::get('name'); $subCategory->description = Request::get('description'); $subCategory->category_id = Request::get('category_id'); //$category->user_id = Auth::user()->id; // Validation and Filtering is sorely needed!! // Seriously, I'm a bad person for leaving that out. if (Auth::user()->id == 1) { $subCategory->save(); return Response::json(array('error' => false, 'categories' => $subCategory->toArray()), 200); } else { return Response::json(array('error' => true, 'reason' => 'Error with user id' . Auth::user()->id), 200); } }
public function saveSubCategory() { $adminId = Session::get('admin_id'); if (!isset($adminId)) { return json_encode(array('message' => 'not logged')); } $name = Input::get('name'); $tempSubCategory = SubCategory::where('name', '=', $name)->where('status', 'active')->get(); if (is_null($tempSubCategory) || $tempSubCategory->isEmpty()) { $category_id = Input::get('category'); $subCategory = new SubCategory(); $subCategory->name = $name; $subCategory->category_id = $category_id; $subCategory->created_at = date("Y-m-d h:i:s"); $subCategory->status = "active"; $subCategory->save(); return json_encode(array('message' => 'done')); } else { return json_encode(array('message' => 'duplicate')); } }