app/Http/Controllers/Admin/EssayAssignmentsController.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, [
            'a_id'              => 'nullable|integer',
            's_name'            => 'nullable|string',
            't_name'            => 'nullable|string',
            'topic'             => 'nullable|string',
            'status'            => 'nullable|string',
            'paid_to_tutor'     => 'nullable|string',
            'price_owed'        => 'nullable|string',
            'a_date_from'       => 'nullable|date',
            'a_date_to'         => 'nullable|date',
            'c_date_from'       => 'nullable|date',
            'c_date_to'         => 'nullable|date',
        ]);
        $q = "1=1 ";
        if (isset($request_data['a_id'])) {
            $q.= " and assignment_num like " . $request_data['a_id'];
        } else $request_data['a_id'] = "";
        if (isset($request_data['topic'])) {
            $q.= " and topic like '%" . $request_data['topic'] . "%'";
        } else $request_data['topic'] = "";
        if (isset($request_data['status'])) {
            $q.= " and status_id like " . $request_data['status'];
        } else $request_data['status'] = "";
        if (isset($request_data['paid_to_tutor'])) {
            $q.= " and paid like " . (string)number_format($request_data['paid_to_tutor'], 2);
        } else $request_data['paid_to_tutor'] = "";
        if (isset($request_data['price_owed'])) {
            $q.= " and owed like " . (string)number_format($request_data['price_owed'], 2);
        } else $request_data['price_owed'] = "";
        $essay_assignments = EssayAssignment::whereRaw($q);
        if (isset($request_data['s_name']))
        {
            $essay_assignments = $essay_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']))
        {
            $essay_assignments = $essay_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'] = "";
        if (isset($request_data['a_date_from']) && isset($request_data['a_date_to'])) {
            $essay_assignments = $essay_assignments->whereBetween('date_assigned',
            [ $request_data['a_date_from'], $request_data['a_date_to'] ]);
        }
        if (!isset($request_data['a_date_from'])) $request_data['a_date_from'] = "";
        if (!isset($request_data['a_date_to'])) $request_data['a_date_to'] = "";
        if (!isset($request_data['c_date_from'])) $request_data['c_date_from'] = "";
        if (!isset($request_data['c_date_to'])) $request_data['c_date_to'] = "";
        $essay_assignments = $essay_assignments->get();
        $statuses = EssayStatus::all();
        $data = [
            'essay_assignments' => $essay_assignments,
            'statuses'          => $statuses,
            'old'               => $request_data,
        ];
        if( count($essay_assignments) != 0 )
        {
            return view('admin.essayassignments.index')->with('data', $data);
        }
        if (count($essay_assignments) == 0) {
            request()->session()->flash('error', "No search results!");
        }
        return view('admin.essayassignments.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 'a_id' => 'nullable|integer' , 's_name' => 'nullable|string' , 't_name' => 'nullable|string' , 'topic' => 'nullable|string' , 'status' => 'nullable|string' , 'paid_to_tutor' => 'nullable|string' , 'price_owed' => 'nullable|string' , 'a_date_from' => 'nullable|date' , 'a_date_to' => 'nullable|date' , 'c_date_from' => 'nullable|date' , 'c_date_to' => 'nullable|date' , ] ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'a_id' ] ) ) { $ q .= "  and assignment_num like  " . $ request_data [ 'a_id' ] ; } else $ request_data [ 'a_id' ] = " " ; if ( isset ( $ request_data [ 'topic' ] ) ) { $ q .= "  and topic like '% " . $ request_data [ 'topic' ] . " %' " ; } else $ request_data [ 'topic' ] = " " ; if ( isset ( $ request_data [ 'status' ] ) ) { $ q .= "  and status_id like  " . $ request_data [ 'status' ] ; } else $ request_data [ 'status' ] = " " ; if ( isset ( $ request_data [ 'paid_to_tutor' ] ) ) { $ q .= "  and paid like  " . ( string ) number_format ( $ request_data [ 'paid_to_tutor' ] , 2 ) ; } else $ request_data [ 'paid_to_tutor' ] = " " ; if ( isset ( $ request_data [ 'price_owed' ] ) ) { $ q .= "  and owed like  " . ( string ) number_format ( $ request_data [ 'price_owed' ] , 2 ) ; } else $ request_data [ 'price_owed' ] = " " ; $ essay_assignments = EssayAssignment :: whereRaw ( $ q ) ; if ( isset ( $ request_data [ 's_name' ] ) ) { $ essay_assignments = $ essay_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' ] ) ) { $ essay_assignments = $ essay_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' ] = " " ; if ( isset ( $ request_data [ 'a_date_from' ] ) && isset ( $ request_data [ 'a_date_to' ] ) ) { $ essay_assignments = $ essay_assignments -> whereBetween ( 'date_assigned' , [ $ request_data [ 'a_date_from' ] , $ request_data [ 'a_date_to' ] ] ) ; } if ( ! isset ( $ request_data [ 'a_date_from' ] ) ) $ request_data [ 'a_date_from' ] = " " ; if ( ! isset ( $ request_data [ 'a_date_to' ] ) ) $ request_data [ 'a_date_to' ] = " " ; if ( ! isset ( $ request_data [ 'c_date_from' ] ) ) $ request_data [ 'c_date_from' ] = " " ; if ( ! isset ( $ request_data [ 'c_date_to' ] ) ) $ request_data [ 'c_date_to' ] = " " ; $ essay_assignments = $ essay_assignments -> get ( ) ; $ statuses = EssayStatus :: all ( ) ; $ data = [ 'essay_assignments' => $ essay_assignments , 'statuses' => $ statuses , 'old' => $ request_data , ] ; if ( count ( $ essay_assignments ) != 0 ) { return view ( 'admin.essayassignments.index' ) -> with ( 'data' , $ data ) ; } if ( count ( $ essay_assignments ) == 0 ) { request ( ) -> session ( ) -> flash ( 'error' , " No search results! " ) ; } return view ( 'admin.essayassignments.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .
// request()->session()->flash('error', null);