Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\CRM\Contact;
  4.  
  5. use App\CRM\Contact\Requests\ContactDestroy;
  6. use App\CRM\Contact\Requests\ContactStore;
  7. use App\CRM\Contact\Requests\ContactUpdate;
  8. use App\Abstractions\Controller;
  9. use EllipseSynergie\ApiResponse\Contracts\Response;
  10. use App\CRM\Contact\Contracts\ContactService as Service;
  11. use App\CRM\Contact\ContactTransformer;
  12.  
  13. class ContactController extends Controller
  14. {
  15. protected $response;
  16. protected $service;
  17.  
  18. public function __construct(
  19. Response $response,
  20. Service $service
  21. ) {
  22. $this->response = $response;
  23. $this->service = $service;
  24. }
  25.  
  26. public function index()
  27. {
  28. $contacts = $this->service->get();
  29. return $this->response->withPaginator($contacts, new ContactTransformer());
  30. }
  31.  
  32. public function show($id)
  33. {
  34. $contact = $this->service->show($id);
  35. return $this->response->withItem($contact, new ContactTransformer());
  36. }
  37.  
  38. public function store(ContactStore $request)
  39. {
  40. $contact = $this->service->store($request);
  41. return $this->response->withItem($contact, new ContactTransformer());
  42. }
  43.  
  44. public function update(ContactUpdate $request, $id)
  45. {
  46. $contact = $this->service->update($request, $id);
  47. return $this->response->withItem($contact, new ContactTransformer());
  48. }
  49.  
  50. public function destroy(ContactDestroy $request, $id)
  51. {
  52. $contact = $this->service->destroy($id);
  53. return $this->response->withItem($contact, new ContactTransformer());
  54. }
  55. }
Add Comment
Please, Sign In to add comment