Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\RestaurantValidation;
- use Illuminate\Http\Request;
- use App\Restaurant;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\View;
- use Carbon\Carbon;
- use Validator;
- use Input;
- use Session;
- use Redirect;
- class RestaurantAPIController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- return Restaurant::all();
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(RestaurantValidation $request)
- {
- $validated = $request->validated();
- $restaurants = Restaurant::create($request->all());
- return response()->json($restaurants, 201);
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function showPostsComments(Request $request)
- {
- $restaurants = Restaurant::find($request['id']);
- foreach ($restaurants->posts as $post)
- {
- echo $post->content;
- foreach ($post->comments as $comment)
- {
- echo $comment->content;
- }
- }
- return response()->json($restaurants, 201);
- }
- public function showCountryCategory(Request $request)
- {
- $restaurants = Restaurant::where('country_id', '=' ,$request['country_id'] )
- ->where('category_id', '=' ,$request['category_id'] )->get();
- return response()->json($restaurants, 201);
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit(Request $request)
- {
- $restaurants = Restaurant::create($request->all());
- return response()->json($restaurants, 201);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request)
- {
- $restaurants = Restaurant::find($request['id']);
- $restaurants->update($request->all());
- return response()->json($restaurants, 200);
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy(Request $request)
- {
- $restaurants = Restaurant::find($request['id']);
- $restaurants->delete();
- return response()->json(null, 204);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement