app/Http/Controllers/Admin/ExpensesController.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, [
            'e_name'        => 'nullable|string',
            'amount'        => 'nullable|string',
            'expense_date'  => 'nullable|date',
            'start_date'    => 'nullable|date',
            'end_date'      => 'nullable|date',
        ]);
        $q = "1=1 ";
        if (isset($request_data['e_name'])) {
            $q .= " and name like '%" . $request_data['e_name'] . "%'";
        } else $request_data['e_name'] = "";
        if (isset($request_data['amount'])) {
            $q.= " and amount like '%".$request_data['amount']."%'";
        } else $request_data['amount'] = "";
        if (isset($request_data['expense_date'])) {
            $q.= " and date like '%".$request_data['expense_date']."%'";
        } else $request_data['expense_date'] = "";
        $expenses_search = Expense::whereRaw($q)->get();
        $expenses_searchdate = Expense::all();
        if (isset($request_data['start_date']) && isset($request_data['end_date']))
        {
            $expenses_searchdate = Expense::whereBetween('date', [
                $request_data['start_date'], $request_data['end_date']
            ])->get();
        } else{
            $request_data['start_date'] = isset($request_data['start_date']) ? $request_data['start_date'] : "";
            $request_data['end_date'] = isset($request_data['end_date']) ? $request_data['end_date'] : "";
        }
        if ($request->input('action') == 'search') {
            $expenses = $expenses_search;
        } else {
            $expenses = $expenses_searchdate;
        }
        $data = [
            'expenses'  => $expenses,
            'old'       => $request_data,
        ];
        if( count($expenses) == 0 ) $request->session()->flash('error', "No search results!");
        return view('admin.expenses.index')->with('data', $data);
    }
public function index ( Request $ request ) { $ request_data = $ this -> validate ( $ request , [ 'e_name' => 'nullable|string' , 'amount' => 'nullable|string' , 'expense_date' => 'nullable|date' , 'start_date' => 'nullable|date' , 'end_date' => 'nullable|date' , ] ) ; $ q = " 1=1  " ; if ( isset ( $ request_data [ 'e_name' ] ) ) { $ q .= "  and name like '% " . $ request_data [ 'e_name' ] . " %' " ; } else $ request_data [ 'e_name' ] = " " ; if ( isset ( $ request_data [ 'amount' ] ) ) { $ q .= "  and amount like '% " . $ request_data [ 'amount' ] . " %' " ; } else $ request_data [ 'amount' ] = " " ; if ( isset ( $ request_data [ 'expense_date' ] ) ) { $ q .= "  and date like '% " . $ request_data [ 'expense_date' ] . " %' " ; } else $ request_data [ 'expense_date' ] = " " ; $ expenses_search = Expense :: whereRaw ( $ q ) -> get ( ) ; $ expenses_searchdate = Expense :: all ( ) ; if ( isset ( $ request_data [ 'start_date' ] ) && isset ( $ request_data [ 'end_date' ] ) ) { $ expenses_searchdate = Expense :: whereBetween ( 'date' , [ $ request_data [ 'start_date' ] , $ request_data [ 'end_date' ] ] ) -> get ( ) ; } else { $ request_data [ 'start_date' ] = isset ( $ request_data [ 'start_date' ] ) ? $ request_data [ 'start_date' ] : " " ; $ request_data [ 'end_date' ] = isset ( $ request_data [ 'end_date' ] ) ? $ request_data [ 'end_date' ] : " " ; } if ( $ request -> input ( 'action' ) == 'search' ) { $ expenses = $ expenses_search ; } else { $ expenses = $ expenses_searchdate ; } $ data = [ 'expenses' => $ expenses , 'old' => $ request_data , ] ; if ( count ( $ expenses ) == 0 ) $ request -> session ( ) -> flash ( 'error' , " No search results! " ) ; return view ( 'admin.expenses.index' ) -> with ( 'data' , $ data ) ; }
Display a listing of the resource.
Display a listing of the resource .