app/Http/Controllers/Tutor/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)
    {
        $validator = Validator::make($request->all(), [
            's_name'            => 'nullable | string',
            'session_date'      => 'nullable | date',
            'session_duration'  => 'nullable | string',
            'session_notes'     => 'nullable | string'
        ]);
        if ($validator -> fails())
        {
            session()->flash('error', $validator->messages()->first());
            return back();
        }
        $request_data = $request->all();
        $myuser = Auth::User();
        $sessions = Session::whereHas('assignments', function($assignment) use ($myuser){
            return $assignment->whereHas('tutors', function($user) use ($myuser){
                return $user->where('id', $myuser->id);
            });
        });
        $q = "1=1 ";
        if (isset($request_data['session_date'])) {
            $q .= " and session_date like '%" . $request_data['session_date'] . "%'";
        } else $request_data['session_date'] = "";
        if (isset($request_data['session_duration'])) {
            $q .= " and session_duration like '%" . $request_data['session_duration'] . "%'";
        } else $request_data['session_duration'] = "";
        if (isset($request_data['session_notes'])) {
            $q .= " and session_notes like '%" . $request_data['session_notes'] . "%'";
        } else $request_data['session_notes'] = "";
        $sessions = $sessions->whereRaw($q);
        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'] = "";
        $sessions = $sessions->get();
        $data = [
            'sessions'  => $sessions,
            'old'       => $request_data,
            'durations' => Session::getAllDurations()
        ];
        return view('tutor.sessions.index') -> with('data', $data);
    }
public function index ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 's_name' => 'nullable | string' , 'session_date' => 'nullable | date' , 'session_duration' => 'nullable | string' , 'session_notes' => 'nullable | string' ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return back ( ) ; } $ request_data = $ request -> all ( ) ; $ myuser = Auth :: User ( ) ; $ sessions = Session :: whereHas ( 'assignments' , function ( $ assignment ) use ( $ myuser ) { return $ assignment -> whereHas ( 'tutors' , function ( $ user ) use ( $ myuser ) { return $ user -> where ( 'id' , $ myuser -> id ) ; } ) ; } ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'session_date' ] ) ) { $ q .= "  and session_date like '% " . $ request_data [ 'session_date' ] . " %' " ; } else $ request_data [ 'session_date' ] = " " ; if ( isset ( $ request_data [ 'session_duration' ] ) ) { $ q .= "  and session_duration like '% " . $ request_data [ 'session_duration' ] . " %' " ; } else $ request_data [ 'session_duration' ] = " " ; if ( isset ( $ request_data [ 'session_notes' ] ) ) { $ q .= "  and session_notes like '% " . $ request_data [ 'session_notes' ] . " %' " ; } else $ request_data [ 'session_notes' ] = " " ; $ sessions = $ sessions -> whereRaw ( $ q ) ; 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' ] = " " ; $ sessions = $ sessions -> get ( ) ; $ data = [ 'sessions' => $ sessions , 'old' => $ request_data , 'durations' => Session :: getAllDurations ( ) ] ; return view ( 'tutor.sessions.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .