app/Http/Controllers/DashboardController.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()
    {
        $now = Carbon::now();
        $allTransactions = Transactions::where('status', 'success')->get();
        $allSales = Transactions::where('status', 'success')->count();
        $monthlySales = Transactions::where('status', 'success')->whereMonth('created_at', $now->month)->count();
        $annualSales = Transactions::where('status', 'success')->whereYear('created_at', $now->year)->count();
        $monthlyTransactions = Transactions::where('status', 'success')->whereMonth('created_at', $now->month)->get();
        $annualTranscations = Transactions::where('status', 'success')->whereYear('created_at', $now->year)->get();
        $incomeTotal = 0;
        $incomeMonthly = 0;
        $incomeAnnual = 0;
        foreach ($allTransactions as $transaction) {
            $incomeTotal+=$transaction->total;
        }
        foreach ($monthlyTransactions as $monthly) {
            $incomeMonthly+=$monthly->total;
        }
        foreach ($annualTranscations as $annual) {
            $incomeAnnual+=$annual->total;
        }
        $january = Transactions::where('status', 'success')->whereMonth('created_at', '01')->sum('total');
        $february = Transactions::where('status', 'success')->whereMonth('created_at', '02')->sum('total');
        $march = Transactions::where('status', 'success')->whereMonth('created_at', '03')->sum('total');
        $april = Transactions::where('status', 'success')->whereMonth('created_at', '04')->sum('total');
        $may = Transactions::where('status', 'success')->whereMonth('created_at', '05')->sum('total');
        $june = Transactions::where('status', 'success')->whereMonth('created_at', '06')->sum('total');
        $july = Transactions::where('status', 'success')->whereMonth('created_at', '07')->sum('total');
        $august = Transactions::where('status', 'success')->whereMonth('created_at', '08')->sum('total');
        $september = Transactions::where('status', 'success')->whereMonth('created_at', '09')->sum('total');
        $october = Transactions::where('status', 'success')->whereMonth('created_at', '10')->sum('total');
        $november = Transactions::where('status', 'success')->whereMonth('created_at', '11')->sum('total');
        $december = Transactions::where('status', 'success')->whereMonth('created_at', '12')->sum('total');
        return view('admin.dashboard', compact('now', 'allSales', 'monthlySales', 'annualSales', 'incomeTotal', 'incomeMonthly', 'incomeAnnual', 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'));
    }
public function index ( ) { $ now = Carbon :: now ( ) ; $ allTransactions = Transactions :: where ( 'status' , 'success' ) -> get ( ) ; $ allSales = Transactions :: where ( 'status' , 'success' ) -> count ( ) ; $ monthlySales = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , $ now -> month ) -> count ( ) ; $ annualSales = Transactions :: where ( 'status' , 'success' ) -> whereYear ( 'created_at' , $ now -> year ) -> count ( ) ; $ monthlyTransactions = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , $ now -> month ) -> get ( ) ; $ annualTranscations = Transactions :: where ( 'status' , 'success' ) -> whereYear ( 'created_at' , $ now -> year ) -> get ( ) ; $ incomeTotal = 0 ; $ incomeMonthly = 0 ; $ incomeAnnual = 0 ; foreach ( $ allTransactions as $ transaction ) { $ incomeTotal += $ transaction -> total ; } foreach ( $ monthlyTransactions as $ monthly ) { $ incomeMonthly += $ monthly -> total ; } foreach ( $ annualTranscations as $ annual ) { $ incomeAnnual += $ annual -> total ; } $ january = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '01' ) -> sum ( 'total' ) ; $ february = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '02' ) -> sum ( 'total' ) ; $ march = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '03' ) -> sum ( 'total' ) ; $ april = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '04' ) -> sum ( 'total' ) ; $ may = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '05' ) -> sum ( 'total' ) ; $ june = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '06' ) -> sum ( 'total' ) ; $ july = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '07' ) -> sum ( 'total' ) ; $ august = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '08' ) -> sum ( 'total' ) ; $ september = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '09' ) -> sum ( 'total' ) ; $ october = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '10' ) -> sum ( 'total' ) ; $ november = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '11' ) -> sum ( 'total' ) ; $ december = Transactions :: where ( 'status' , 'success' ) -> whereMonth ( 'created_at' , '12' ) -> sum ( 'total' ) ; return view ( 'admin.dashboard' , compact ( 'now' , 'allSales' , 'monthlySales' , 'annualSales' , 'incomeTotal' , 'incomeMonthly' , 'incomeAnnual' , 'january' , 'february' , 'march' , 'april' , 'may' , 'june' , 'july' , 'august' , 'september' , 'october' , 'november' , 'december' ) ) ; }
Display a listing of the resource.
Display a listing of the resource .