app/Http/Controllers/Admin/SessionsController.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)
    {
        $request_data = $this->validate($request, [
            't_name'            => 'nullable|string',
            's_name'            => 'nullable|string',
            'session_duration'  => 'nullable|string',
            'date_submission'   => 'nullable|date',
            'session_date'      => 'nullable|date',
        ]);
        $sessions = Session::has('assignments');
        if (isset($request_data['date_submission'])) {
            $sessions = $sessions->where('date_submission', $request_data['date_submission']);
        } else $request_data['date_submission'] = "";
        if (isset($request_data['session_date'])) {
            $sessions = $sessions->where('session_date', $request_data['session_date']);
        } else $request_data['session_date'] = "";
        if (isset($request_data['s_name'])) {
            $sessions = $sessions->whereHas('assignments', function($assignment) use ($request_data) {
                return $assignment->whereHas('students', function($student) use ($request_data) {
                    return $student->where('fname', 'like', "%" . $request_data['s_name'] . "%")
                                    ->orwhere('lname', 'like', "%" . $request_data['s_name'] . "%");
                    });
                });
        } else $request_data['s_name'] = "";
        if (isset($request_data['t_name'])) {
            $sessions = $sessions->whereHas('assignments', function($assignment) use ($request_data) {
                return $assignment->whereHas('tutors', function($tutor) use ($request_data) {
                    return $tutor->where('fname', 'like', "%" . $request_data['t_name'] . "%")
                                    ->orwhere('lname', 'like', "%" . $request_data['t_name'] . "%");
                    });
                });
        } else $request_data['t_name'] = "";
        if (isset($request_data['session_duration'])) {
           $sessions = $sessions->where('session_duration', 'like', $request_data['session_duration']);
        } else $request_data['session_duration'] = "";
        $sessions = $sessions->get();
        $session_durations = Array();
        foreach(Session::all() as $session)
        {
            if ($session->session_duration < 0.50) continue;
            $session_durations[$session->session_duration] = Session::getDuration($session->session_duration);
        }
        ksort($session_durations);
        $data = [
            'sessions'          => $sessions,
            'session_durations' => $session_durations,
            'old'               => $request_data,
        ];
        if( count($sessions) != 0 ) return view('admin.sessions.index')->with('data', $data);
        request()->session()->flash('error', "No search results!");
        return view('admin.sessions.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 't_name' => 'nullable|string' , 's_name' => 'nullable|string' , 'session_duration' => 'nullable|string' , 'date_submission' => 'nullable|date' , 'session_date' => 'nullable|date' , ] ) ; $ sessions = Session :: has ( 'assignments' ) ; if ( isset ( $ request_data [ 'date_submission' ] ) ) { $ sessions = $ sessions -> where ( 'date_submission' , $ request_data [ 'date_submission' ] ) ; } else $ request_data [ 'date_submission' ] = " " ; if ( isset ( $ request_data [ 'session_date' ] ) ) { $ sessions = $ sessions -> where ( 'session_date' , $ request_data [ 'session_date' ] ) ; } else $ request_data [ 'session_date' ] = " " ; if ( isset ( $ request_data [ 's_name' ] ) ) { $ sessions = $ sessions -> whereHas ( 'assignments' , function ( $ assignment ) use ( $ request_data ) { return $ assignment -> whereHas ( 'students' , function ( $ student ) use ( $ request_data ) { return $ student -> where ( 'fname' , 'like' , " % " . $ request_data [ 's_name' ] . " % " ) -> orwhere ( 'lname' , 'like' , " % " . $ request_data [ 's_name' ] . " % " ) ; } ) ; } ) ; } else $ request_data [ 's_name' ] = " " ; if ( isset ( $ request_data [ 't_name' ] ) ) { $ sessions = $ sessions -> whereHas ( 'assignments' , function ( $ assignment ) use ( $ request_data ) { return $ assignment -> whereHas ( 'tutors' , function ( $ tutor ) use ( $ request_data ) { return $ tutor -> where ( 'fname' , 'like' , " % " . $ request_data [ 't_name' ] . " % " ) -> orwhere ( 'lname' , 'like' , " % " . $ request_data [ 't_name' ] . " % " ) ; } ) ; } ) ; } else $ request_data [ 't_name' ] = " " ; if ( isset ( $ request_data [ 'session_duration' ] ) ) { $ sessions = $ sessions -> where ( 'session_duration' , 'like' , $ request_data [ 'session_duration' ] ) ; } else $ request_data [ 'session_duration' ] = " " ; $ sessions = $ sessions -> get ( ) ; $ session_durations = Array ( ) ; foreach ( Session :: all ( ) as $ session ) { if ( $ session -> session_duration < 0.50 ) continue ; $ session_durations [ $ session -> session_duration ] = Session :: getDuration ( $ session -> session_duration ) ; } ksort ( $ session_durations ) ; $ data = [ 'sessions' => $ sessions , 'session_durations' => $ session_durations , 'old' => $ request_data , ] ; if ( count ( $ sessions ) != 0 ) return view ( 'admin.sessions.index' ) -> with ( 'data' , $ data ) ; request ( ) -> session ( ) -> flash ( 'error' , " No search results! " ) ; return view ( 'admin.sessions.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .