Overview
TheDashboardController is an invokable controller that generates the main dashboard view for authenticated users. It aggregates financial data including accounts, net worth, transaction summaries, and chart data for visualization.
Namespace: App\Http\Controllers
Extends: Controller
Routes
| Method | URI | Name | Middleware |
|---|---|---|---|
| GET | /dashboard | dashboard | auth, verified |
Methods
__invoke()
The main invokable method that handles dashboard requests and returns the dashboard view with aggregated financial data.Chart service for generating net worth data visualization
Chart service for generating spending data visualization
Returns
Returns an Illuminate view with the following data:groupedTransactions- Recent transactions grouped by date (last 5)groupedExpenses- Recent expense transactions grouped by date (last 5)groupedIncomes- Recent income transactions grouped by date (last 5)accounts- All user accounts with their transactionsnetWorth- Latest net worth valuedateRanges- Date ranges for the net worth chartnetworthChartData- Net worth data points for chartingspendingChartData- Spending amounts rounded to 2 decimalsspendingChartLabels- Labels for the spending charttotalExpenses- Sum of all expense transactionstotalIncomes- Sum of all income transactions
Example Request
Example Response
Private Methods
getUserAccounts()
Retrieves all accounts for a specific user with their associated transactions.The ID of the user
getLatestNetWorth()
Fetches the most recent net worth value for a user.The ID of the user
getTransactionTotals()
Calculates total expenses and incomes for a user by joining with categories.The ID of the user
total_expenses and total_incomes properties
getGroupedTransactions()
Fetches and groups the 5 most recent transactions by type (all, expenses, incomes).The ID of the user
[groupedTransactions, groupedExpenses, groupedIncomes]
fetchAndGroupTransactions()
Fetches transactions optionally filtered by type and groups them by date.The ID of the user
Optional transaction type filter (
expense or income)Dependencies
App\Charts\NetworthChart- Service for generating net worth chart dataApp\Charts\SpendingChart- Service for generating spending chart dataApp\Models\Account- Account modelApp\Models\NetWorth- Net worth modelApp\Models\Transaction- Transaction modelIlluminate\Support\Facades\Auth- Authentication facade
Authorization
This controller requires the user to be authenticated and have a verified email address via theauth and verified middleware.