Exemplo n.º 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (is_numeric($id)) {
         $root = Root::where('id', $id)->first();
     } else {
         $root = Root::find($id);
     }
     if ($root) {
         $root->delete();
         return response(['message' => "Successfully deleted Root with id {$id}"], 200);
     }
     return response(['message' => "Unable to delete Root with id {$id}"], 400);
 }
 /**
  * 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();
 }