Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Author;
  6. use App\Http\Requests\AuthorStoreRequest;
  7. use Illuminate\Http\Request;
  8.  
  9. class AuthorController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. *
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function index()
  17. {
  18. //
  19. $authors = Author::all();
  20. $response=[
  21. 'message'=>'Lista de Autores',
  22. 'data'=>$authors,
  23. 'result'=>'ok'
  24. ];
  25.  
  26. return response($response);
  27. }
  28.  
  29. /**
  30. * Show the form for creating a new resource.
  31. *
  32. * @return \Illuminate\Http\Response
  33. */
  34. public function create()
  35. {
  36. //
  37. }
  38.  
  39. /**
  40. * Store a newly created resource in storage.
  41. *
  42. * @param \Illuminate\Http\Request $request
  43. * @return \Illuminate\Http\Response
  44. */
  45. public function store(AuthorStoreRequest $request)
  46. {
  47. //
  48. $data=$request->all(); //array com as informações q mandar por post
  49.  
  50. $author=Author::create($data);
  51.  
  52. $response=[
  53. 'message'=>'Autor Adicionado',
  54. 'data'=>$author,
  55. 'result'=>'ok'
  56. ];
  57.  
  58. return response($response);
  59. }
  60.  
  61. /**
  62. * Display the specified resource.
  63. *
  64. * @param \App\Author $author
  65. * @return \Illuminate\Http\Response
  66. */
  67. public function show(Author $author)
  68. {
  69. //
  70. $response=[
  71. 'message'=>'Autor selecionado',
  72. 'data'=>$author,
  73. 'result'=>'ok'
  74. ];
  75.  
  76. return response($response);
  77. }
  78.  
  79. /**
  80. * Show the form for editing the specified resource.
  81. *
  82. * @param \App\Author $author
  83. * @return \Illuminate\Http\Response
  84. */
  85. public function edit(Author $author)
  86. {
  87. //
  88.  
  89. }
  90.  
  91. /**
  92. * Update the specified resource in storage.
  93. *
  94. * @param \Illuminate\Http\Request $request
  95. * @param \App\Author $author
  96. * @return \Illuminate\Http\Response
  97. */
  98. public function update(AuthorStoreRequest $request, Author $author)
  99. {
  100. //
  101. $data=$request->all();
  102.  
  103. $author->update($data);
  104.  
  105. $response=[
  106. 'message'=>'Autor Atualizado',
  107. 'data'=>$author,
  108. 'result'=>'ok'
  109. ];
  110. return response($response);
  111.  
  112. }
  113.  
  114. /**
  115. * Remove the specified resource from storage.
  116. *
  117. * @param \App\Author $author
  118. * @return \Illuminate\Http\Response
  119. */
  120. public function destroy(Author $author)
  121. {
  122. //
  123. $author->delete();
  124. $response=[
  125. 'message'=>'Autor Apagado',
  126. 'data'=>$author,
  127. 'result'=>'ok'
  128. ];
  129.  
  130. return response($response);
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement