app/Http/Controllers/Api/MovieController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
      $movies = Movie::orderBy('updated_at', 'desc');
      if($request->category_id) {
        $movies = $movies->whereHas('categories', function($query) use ($request) {
          $query->where('category_id', $request->category_id);
        });
      }
      $movies = $movies->get();
      return response()->json($movies);
    }
public function index ( Request $ request ) { $ movies = Movie :: orderBy ( 'updated_at' , 'desc' ) ; if ( $ request -> category_id ) { $ movies = $ movies -> whereHas ( 'categories' , function ( $ query ) use ( $ request ) { $ query -> where ( 'category_id' , $ request -> category_id ) ; } ) ; } $ movies = $ movies -> get ( ) ; return response ( ) -> json ( $ movies ) ; }
Display a listing of the resource.
Display a listing of the resource .