app/Http/Controllers/Admin/ReceivedPaymentsController.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, [
            'id'            => 'nullable|integer',
            's_name'        => 'nullable|string',
            'status_id'     => 'nullable|integer',
            'date_added'    => 'nullable|date',
        ]);
        $q = "1=1 ";
        if (isset($request_data['id'])) {
            $q .= " and id like '%" . $request_data['id'] . "%'";
        } else $request_data['id'] = "";
        if (isset($request_data['date_added'])) {
            $q.= " and created_at like '%".$request_data['date_added']."%'";
        } else $request_data['date_added'] = "";
        if (isset($request_data['status_id'])) {
            $q.= " and status_id like '%".$request_data['status_id']."%'";
        } else $request_data['status_id'] = "";
        $orders = Order::has('users')->whereRaw($q);
        if (isset($request_data['s_name'])) {
            $orders = $orders->whereHas('users', function($user) use ($request_data) {
            return $user->where('fname', 'like', "%" . $request_data['s_name'] . "%")
                ->orwhere('lname', 'like', "%" . $request_data['s_name'] . "%");
            });
        } else $request_data['s_name'] = "";
        $orders = $orders->get();
        $order_statuses = OrderStatus::all();
        $data = [
            'orders'    => $orders,
            'statuses'  => $order_statuses,
            'old'       => $request_data,
        ];
       if( count($orders) == 0 ) $request->session()->flash('error', "No search results!");
        return view('admin.receivedpayments.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 'id' => 'nullable|integer' , 's_name' => 'nullable|string' , 'status_id' => 'nullable|integer' , 'date_added' => 'nullable|date' , ] ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'id' ] ) ) { $ q .= "  and id like '% " . $ request_data [ 'id' ] . " %' " ; } else $ request_data [ 'id' ] = " " ; if ( isset ( $ request_data [ 'date_added' ] ) ) { $ q .= "  and created_at like '% " . $ request_data [ 'date_added' ] . " %' " ; } else $ request_data [ 'date_added' ] = " " ; if ( isset ( $ request_data [ 'status_id' ] ) ) { $ q .= "  and status_id like '% " . $ request_data [ 'status_id' ] . " %' " ; } else $ request_data [ 'status_id' ] = " " ; $ orders = Order :: has ( 'users' ) -> whereRaw ( $ q ) ; if ( isset ( $ request_data [ 's_name' ] ) ) { $ orders = $ orders -> whereHas ( 'users' , function ( $ user ) use ( $ request_data ) { return $ user -> where ( 'fname' , 'like' , " % " . $ request_data [ 's_name' ] . " % " ) -> orwhere ( 'lname' , 'like' , " % " . $ request_data [ 's_name' ] . " % " ) ; } ) ; } else $ request_data [ 's_name' ] = " " ; $ orders = $ orders -> get ( ) ; $ order_statuses = OrderStatus :: all ( ) ; $ data = [ 'orders' => $ orders , 'statuses' => $ order_statuses , 'old' => $ request_data , ] ; if ( count ( $ orders ) == 0 ) $ request -> session ( ) -> flash ( 'error' , " No search results! " ) ; return view ( 'admin.receivedpayments.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .