app/Http/Controllers/Admin/PaychequesController.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',
            'num_of_sessions'   => 'nullable|integer',
            'date_added'        => 'nullable|date',
            'status'            => 'nullable|string'
        ]);
        $q = "1=1 ";
        if (isset($request_data['num_of_sessions'])) {
            $q .= " and num like '%" . $request_data['num_of_sessions'] . "%'";
        } else $request_data['num_of_sessions'] = "";
        if (isset($request_data['date_added'])) {
            $q.= " and date_added like '%".$request_data['date_added']."%'";
        } else $request_data['date_added'] = "";
        if (isset($request_data['status'])) {
            $q.= " and status like '%".$request_data['status']."%'";
        } else $request_data['status'] = "";
        $paycheques = Paycheque::whereRaw($q);
        if (isset($request_data['t_name'])) {
            $paycheques = $paycheques->whereHas('users', function($user) use ($request_data) {
            return $user->where('fname', 'like', "%" . $request_data['t_name'] . "%")
                ->orwhere('lname', 'like', "%" . $request_data['t_name'] . "%");
            });
        } else $request_data['t_name'] = "";
        $paycheques = $paycheques->get();
        $data = [
            'paycheques'   => $paycheques,
            'old'        => $request_data,
        ];
       if( count($paycheques) == 0 ) $request->session()->flash('error', "No search results!");
        return view('admin.paycheques.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 't_name' => 'nullable|string' , 'num_of_sessions' => 'nullable|integer' , 'date_added' => 'nullable|date' , 'status' => 'nullable|string' ] ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'num_of_sessions' ] ) ) { $ q .= "  and num like '% " . $ request_data [ 'num_of_sessions' ] . " %' " ; } else $ request_data [ 'num_of_sessions' ] = " " ; if ( isset ( $ request_data [ 'date_added' ] ) ) { $ q .= "  and date_added like '% " . $ request_data [ 'date_added' ] . " %' " ; } else $ request_data [ 'date_added' ] = " " ; if ( isset ( $ request_data [ 'status' ] ) ) { $ q .= "  and status like '% " . $ request_data [ 'status' ] . " %' " ; } else $ request_data [ 'status' ] = " " ; $ paycheques = Paycheque :: whereRaw ( $ q ) ; if ( isset ( $ request_data [ 't_name' ] ) ) { $ paycheques = $ paycheques -> whereHas ( 'users' , function ( $ user ) use ( $ request_data ) { return $ user -> where ( 'fname' , 'like' , " % " . $ request_data [ 't_name' ] . " % " ) -> orwhere ( 'lname' , 'like' , " % " . $ request_data [ 't_name' ] . " % " ) ; } ) ; } else $ request_data [ 't_name' ] = " " ; $ paycheques = $ paycheques -> get ( ) ; $ data = [ 'paycheques' => $ paycheques , 'old' => $ request_data , ] ; if ( count ( $ paycheques ) == 0 ) $ request -> session ( ) -> flash ( 'error' , " No search results! " ) ; return view ( 'admin.paycheques.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .