Advertisement
Guest User

Untitled

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4. use App\Http\Requests\RestaurantValidation;
  5. use Illuminate\Http\Request;
  6. use App\Restaurant;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\View;
  9. use Carbon\Carbon;
  10. use Validator;
  11. use Input;
  12. use Session;
  13. use Redirect;
  14.  
  15. class RestaurantAPIController extends Controller
  16. {
  17. /**
  18. * Display a listing of the resource.
  19. *
  20. * @return \Illuminate\Http\Response
  21. */
  22. public function index()
  23. {
  24. return Restaurant::all();
  25. }
  26.  
  27. /**
  28. * Show the form for creating a new resource.
  29. *
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function create()
  33. {
  34. //
  35. }
  36.  
  37. /**
  38. * Store a newly created resource in storage.
  39. *
  40. * @param \Illuminate\Http\Request $request
  41. * @return \Illuminate\Http\Response
  42. */
  43. public function store(RestaurantValidation $request)
  44. {
  45. $validated = $request->validated();
  46. $restaurants = Restaurant::create($request->all());
  47. return response()->json($restaurants, 201);
  48. }
  49.  
  50. /**
  51. * Display the specified resource.
  52. *
  53. * @param int $id
  54. * @return \Illuminate\Http\Response
  55. */
  56. public function showPostsComments(Request $request)
  57. {
  58. $restaurants = Restaurant::find($request['id']);
  59. foreach ($restaurants->posts as $post)
  60. {
  61. echo $post->content;
  62. foreach ($post->comments as $comment)
  63. {
  64. echo $comment->content;
  65. }
  66. }
  67.  
  68. return response()->json($restaurants, 201);
  69. }
  70.  
  71. public function showCountryCategory(Request $request)
  72. {
  73. $restaurants = Restaurant::where('country_id', '=' ,$request['country_id'] )
  74. ->where('category_id', '=' ,$request['category_id'] )->get();
  75. return response()->json($restaurants, 201);
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82. /**
  83. * Show the form for editing the specified resource.
  84. *
  85. * @param int $id
  86. * @return \Illuminate\Http\Response
  87. */
  88. public function edit(Request $request)
  89. {
  90. $restaurants = Restaurant::create($request->all());
  91. return response()->json($restaurants, 201);
  92. }
  93.  
  94. /**
  95. * Update the specified resource in storage.
  96. *
  97. * @param \Illuminate\Http\Request $request
  98. * @param int $id
  99. * @return \Illuminate\Http\Response
  100. */
  101. public function update(Request $request)
  102. {
  103. $restaurants = Restaurant::find($request['id']);
  104. $restaurants->update($request->all());
  105. return response()->json($restaurants, 200);
  106. }
  107.  
  108. /**
  109. * Remove the specified resource from storage.
  110. *
  111. * @param int $id
  112. * @return \Illuminate\Http\Response
  113. */
  114. public function destroy(Request $request)
  115. {
  116. $restaurants = Restaurant::find($request['id']);
  117. $restaurants->delete();
  118. return response()->json(null, 204);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement