/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $attrs = Input::get('data.attributes'); if (is_numeric($id)) { $root = Root::findOrFail($id); } else { $root = Root::where('root_slug', $id)->firstOrFail(); } $root->fill($attrs); $root->save(); return $this->res->item($root)->send(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if (!Input::has('data.relationships.root')) { return response('No Relationship sent', 400); } if (!Input::has('data.relationships.root.data.id')) { return response('No ID sent', 400); } $root_id = Input::get('data.relationships.root.data.id'); if (is_numeric($root_id)) { $root = Root::findOrFail($root_id); } else { $root = Root::where('root_slug', $root_id)->firstOrFail(); } $cognate = new Cognate(); $cognate->fill(Input::get('data.attributes')); $root->cognates()->save($cognate); $cognate->root; return $this->res->item($cognate)->send(); }