app/Http/Controllers/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()
    {
        if (Auth::user()->companyProfile->count() == 0)
            return redirect()->route('admin.profile')->withErrors(['error' => 'Provide company profile first']);
        $travel_date = null;
        if (request('travel_date')) {
            $travel_date = request('travel_date');
        }
        $bookings = Booking::query();
        $bookings = $bookings->select('*', 'bookings.id as book_id')
            ->join('rides', 'ride_id', 'rides.id')
            ->join('bus_company_profiles as company', 'rides.company_id', 'company.id')
            ->where('company.id', Auth::user()->company()->id)
            ->when($travel_date, function ($query) {
                return $query->where('travel_date', request('travel_date'));
            })
            ->orderBy('bookings.updated_at', 'desc')
            ->orderBy('travel_date', 'asc');
        if (request('status') && request('status') != 'all') {
            $bookings->where('status', request('status'));
        }
        $bookings = $bookings->get();
        return view('bookings.index', compact('bookings'));
    }
public function index ( ) { if ( Auth :: user ( ) -> companyProfile -> count ( ) == 0 ) return redirect ( ) -> route ( 'admin.profile' ) -> withErrors ( [ 'error' => 'Provide company profile first' ] ) ; $ travel_date = null ; if ( request ( 'travel_date' ) ) { $ travel_date = request ( 'travel_date' ) ; } $ bookings = Booking :: query ( ) ; $ bookings = $ bookings -> select ( '*' , 'bookings.id as book_id' ) -> join ( 'rides' , 'ride_id' , 'rides.id' ) -> join ( 'bus_company_profiles as company' , 'rides.company_id' , 'company.id' ) -> where ( 'company.id' , Auth :: user ( ) -> company ( ) -> id ) -> when ( $ travel_date , function ( $ query ) { return $ query -> where ( 'travel_date' , request ( 'travel_date' ) ) ; } ) -> orderBy ( 'bookings.updated_at' , 'desc' ) -> orderBy ( 'travel_date' , 'asc' ) ; if ( request ( 'status' ) && request ( 'status' ) != 'all' ) { $ bookings -> where ( 'status' , request ( 'status' ) ) ; } $ bookings = $ bookings -> get ( ) ; return view ( 'bookings.index' , compact ( 'bookings' ) ) ; }
Display a listing of the resource.
Display a listing of the resource .
//