app/Http/Controllers/Admin/RideController.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']);
        if (request('ride_date')) {
            $ride_date = request('ride_date');
            $dayName = Str::lower(Carbon::parse($ride_date)->dayName);
        } else {
            $ride_date = null;
            $dayName = null;
        }
        $rides = Auth::user()->company()->rides();
        $rides = $rides->when($ride_date, function ($query) use ($ride_date, $dayName) {
            $query->where('ride_date', $ride_date)
                ->orWhereHas('schedule', function ($query) use ($dayName, $ride_date) {
                    $query->where($dayName, true)
                        ->where(function (Builder $query) use ($ride_date, $dayName) {
                            $query->where('start_date', '<=', $ride_date);
                        })->where(function (Builder $query) use ($ride_date, $dayName) {
                            $query->where('end_date', '>=', $ride_date)
                                ->orWhereNull('end_date');
                        });
                });
        });
        if (request('ride_type') && request('ride_type') != 'all') {
            $rides->where('ride_type', request('ride_type'));
        }
        $rides = $rides->orderBy('departure_time', 'asc')
            ->paginate(10);
        return view('admin.rides.index', compact('rides'))
            ->with('i', (request()->input('page', 1) - 1) * 10);
    }
public function index ( ) { if ( Auth :: user ( ) -> companyProfile -> count ( ) == 0 ) return redirect ( ) -> route ( 'admin.profile' ) -> withErrors ( [ 'error' => 'Provide company profile first' ] ) ; if ( request ( 'ride_date' ) ) { $ ride_date = request ( 'ride_date' ) ; $ dayName = Str :: lower ( Carbon :: parse ( $ ride_date ) -> dayName ) ; } else { $ ride_date = null ; $ dayName = null ; } $ rides = Auth :: user ( ) -> company ( ) -> rides ( ) ; $ rides = $ rides -> when ( $ ride_date , function ( $ query ) use ( $ ride_date , $ dayName ) { $ query -> where ( 'ride_date' , $ ride_date ) -> orWhereHas ( 'schedule' , function ( $ query ) use ( $ dayName , $ ride_date ) { $ query -> where ( $ dayName , true ) -> where ( function ( Builder $ query ) use ( $ ride_date , $ dayName ) { $ query -> where ( 'start_date' , '<=' , $ ride_date ) ; } ) -> where ( function ( Builder $ query ) use ( $ ride_date , $ dayName ) { $ query -> where ( 'end_date' , '>=' , $ ride_date ) -> orWhereNull ( 'end_date' ) ; } ) ; } ) ; } ) ; if ( request ( 'ride_type' ) && request ( 'ride_type' ) != 'all' ) { $ rides -> where ( 'ride_type' , request ( 'ride_type' ) ) ; } $ rides = $ rides -> orderBy ( 'departure_time' , 'asc' ) -> paginate ( 10 ) ; return view ( 'admin.rides.index' , compact ( 'rides' ) ) -> with ( 'i' , ( request ( ) -> input ( 'page' , 1 ) - 1 ) * 10 ) ; }
Display a listing of the resource.
Display a listing of the resource .
//