app/Http/Controllers/Admin/TutorAssignmentsController.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, [
            's_name' => 'nullable|string',
            't_name' => 'nullable|string',
            'a_date' => 'nullable|date',
        ]);
        $q = "1=1 ";
        if (isset($request_data['a_date'])) {
            $q.= " and created_at like '%".$request_data['a_date']."%'";
        }
        else $request_data['a_date'] = "";
        $assignments = Assignment::query()->whereRaw($q);
        if (isset($request_data['s_name']))
        {
            $assignments = $assignments->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']))
        {
            $assignments = $assignments->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'] = "";
        $assignments = $assignments->get();
        $data = [
            'assignments'   => $assignments,
            'old'           => [
                't_name'    => $request_data['t_name'],
                's_name'    => $request_data['s_name'],
                'a_date'    => $request_data['a_date'],
            ]
        ];
        if( count($assignments) != 0 )
        {
            return view('admin.tutorassignments.index')->with('data', $data);
        }
        request()->session()->flash('error', null);
        if (count($assignments) == 0) {
            request()->session()->flash('error', "No search results!");
        }
        return view('admin.tutorassignments.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 's_name' => 'nullable|string' , 't_name' => 'nullable|string' , 'a_date' => 'nullable|date' , ] ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'a_date' ] ) ) { $ q .= "  and created_at like '% " . $ request_data [ 'a_date' ] . " %' " ; } else $ request_data [ 'a_date' ] = " " ; $ assignments = Assignment :: query ( ) -> whereRaw ( $ q ) ; if ( isset ( $ request_data [ 's_name' ] ) ) { $ assignments = $ assignments -> 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' ] ) ) { $ assignments = $ assignments -> 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' ] = " " ; $ assignments = $ assignments -> get ( ) ; $ data = [ 'assignments' => $ assignments , 'old' => [ 't_name' => $ request_data [ 't_name' ] , 's_name' => $ request_data [ 's_name' ] , 'a_date' => $ request_data [ 'a_date' ] , ] ] ; if ( count ( $ assignments ) != 0 ) { return view ( 'admin.tutorassignments.index' ) -> with ( 'data' , $ data ) ; } request ( ) -> session ( ) -> flash ( 'error' , null ) ; if ( count ( $ assignments ) == 0 ) { request ( ) -> session ( ) -> flash ( 'error' , " No search results! " ) ; } return view ( 'admin.tutorassignments.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .
//dd($datas['old']['t_name']); //     $assignmentIDs = Assignment::where('name', 'like' "%" . $name . "%")->get(['id'])->pluck('id')->toArray(); //      $assignments = Assignment::whereNotIn('id', $assignmentIDs)->get();