first(); } if (! $contact instanceof Contact) { //return $this->noContent(); return $this->errorInternal('No query results for model [' . Contact::class . '] ' . $id); } return new Resource($contact); } /** * Store a newly created resource in storage. * * @param $request * @return \Illuminate\Http\JsonResponse */ public function store(Request $request) { $contact = $this->dispatch(new CreateContact($request)); return $this->created(route('api.contacts.show', $contact->id), new Resource($contact)); } /** * Update the specified resource in storage. * * @param $contact * @param $request * @return \Illuminate\Http\JsonResponse */ public function update(Contact $contact, Request $request) { $contact = $this->dispatch(new UpdateContact($contact, $request)); return new Resource($contact->fresh()); } /** * Enable the specified resource in storage. * * @param Contact $contact * @return \Illuminate\Http\JsonResponse */ public function enable(Contact $contact) { $contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 1]))); return new Resource($contact->fresh()); } /** * Disable the specified resource in storage. * * @param Contact $contact * @return \Illuminate\Http\JsonResponse */ public function disable(Contact $contact) { try { $contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 0]))); return new Resource($contact->fresh()); } catch(\Exception $e) { $this->errorUnauthorized($e->getMessage()); } } /** * Remove the specified resource from storage. * * @param Contact $contact * @return \Illuminate\Http\Response */ public function destroy(Contact $contact) { try { $this->dispatch(new DeleteContact($contact)); return $this->noContent(); } catch(\Exception $e) { $this->errorUnauthorized($e->getMessage()); } } }