/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = Auth::user()->id; $note = new ListItem(); $note->user_id = $user; $note->category_id = $request->category; $note->text = $request->text; $note->save(); return Response::json($note, 200); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { try { if ($request->input('title') == "") { throw new ListItemException('store : title can\'t be null'); } $id = Auth::user()->id; $listItem = new ListItem(); $listItem->title = $request->input('title'); $listItem->content = $request->input('content'); $listItem->time = date_create()->format('Y-m-d H:i:s'); $listItem->belong = $id; $listItem->isuse = 1; $listItem->save(); return Response()->json(['errno' => 0, 'type' => 'succ', 'msg' => (object) array()]); } catch (ListItemException $e) { return Response()->json(['errno' => 2, 'type' => 'fail', 'msg' => $e->getMessage()]); } catch (Exception $e) { Log::error($e); return Response()->json(['errno' => 1, 'type' => 'fail', 'msg' => 'Whoops, looks like something went wrong']); } }