app/Http/Controllers/API/BookingController.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($status)
    {
        $bookings = request()->user()->bookings;
        $today = Carbon::now()->format('Y-m-d');
        if ($status == 'active') {
            $bookings = $bookings
                ->filter(function ($book) use ($today) {
                    return ($book->status == 'confirmed' || $book->status == 'done') && $book->travel_date >= $today;
                });
        }
        if ($status == 'inactive') {
            $bookings = $bookings->where('travel_date', '<', $today);
        }
        if ($status == 'cancelled') {
            $bookings = $bookings->filter(function ($book) {
                return !($book->status == 'confirmed' || $book->status == 'done');
            });
        }
        $bookings = $bookings->sortBy('travel_date');
        return response()->json(BookingResource::collection($bookings));
    }
public function index ( $ status ) { $ bookings = request ( ) -> user ( ) -> bookings ; $ today = Carbon :: now ( ) -> format ( 'Y-m-d' ) ; if ( $ status == 'active' ) { $ bookings = $ bookings -> filter ( function ( $ book ) use ( $ today ) { return ( $ book -> status == 'confirmed' || $ book -> status == 'done' ) && $ book -> travel_date >= $ today ; } ) ; } if ( $ status == 'inactive' ) { $ bookings = $ bookings -> where ( 'travel_date' , '<' , $ today ) ; } if ( $ status == 'cancelled' ) { $ bookings = $ bookings -> filter ( function ( $ book ) { return ! ( $ book -> status == 'confirmed' || $ book -> status == 'done' ) ; } ) ; } $ bookings = $ bookings -> sortBy ( 'travel_date' ) ; return response ( ) -> json ( BookingResource :: collection ( $ bookings ) ) ; }
Display a listing of the resource.
Display a listing of the resource .