Add index function to TransactionController
MODIFY
app/Http/Controllers/TransactionController.php
app/Http/Controllers/TransactionController.php
namespace App\Http\Controllers;
+use Carbon\Carbon;
use Illuminate\Http\Request;
class TransactionController extends Controller {
+ public function index() {
+ $yearMonths = [];
+
+ // Populate yearMonths with earnings
+ foreach (session('space')->earnings as $earning) {
+ $i = Carbon::parse($earning->happened_on)->format('Y-m');
+
+ if (!isset($yearMonths[$i])) {
+ $yearMonths[$i] = [];
+ }
+
+ $yearMonths[$i][] = $earning;
+ }
+
+ // Populate yearMonths with spendings
+ foreach (session('space')->spendings as $spending) {
+ $i = Carbon::parse($spending->happened_on)->format('Y-m');
+
+ if (!isset($yearMonths[$i])) {
+ $yearMonths[$i] = [];
+ }
+
+ $yearMonths[$i][] = $spending;
+ }
+
+ // Sort transactions
+ foreach ($yearMonths as &$yearMonth) {
+ usort($yearMonth, function ($a, $b) {
+ return $a->happened_on < $b->happened_on;
+ });
+ }
+
+ // Sort yearMonths
+ krsort($yearMonths);
+
+ return view('transactions.index', compact('yearMonths'));
+ }
+
public function create() {
$tags = [];

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
<a href="/dashboard" {!! (Request::path() == 'dashboard') ? 'class="active"' : '' !!}><i class="far fa-home fa-sm color-blue"></i> <span class="hidden ml-05">{{ __('general.dashboard') }}</span></a>
</li>
<li>
- <a href="/recurrings" {!! (Request::path() == 'recurrings') ? 'class="active"' : '' !!}><i class="far fa-recycle fa-sm color-green"></i> <span class="hidden ml-05">{{ __('models.recurrings') }}</span></a>
+ <a href="/transactions" {!! (Request::path() == 'transactions') ? 'class="active"' : '' !!}><i class="far fa-exchange-alt fa-sm color-green"></i> <span class="hidden ml-05">{{ __('models.transactions') }}</span></a>
</li>
<li>
<a href="/tags" {!! (Request::path() == 'tags') ? 'class="active"' : '' !!}><i class="far fa-tag fa-sm color-red"></i> <span class="hidden ml-05">{{ __('models.tags') }}</span></a>

ADD
resources/views/transactions/index.blade.php
+@extends('layout')
+
+@section('title', __('models.transactions'))
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>{{ __('models.transactions') }}</h2>
+ @foreach ($yearMonths as $key => $transactions)
+ <h2 class="mt-3 mb-2">{{ $key }}</h2>
+ <div class="box">
+ @foreach ($transactions as $transaction)
+ <div class="box__section row">
+ <div class="row__column">{{ $transaction->description }}</div>
+ <div class="row__column">
+ @if ($transaction->tag)
+ @include('partials.tag', ['payload' => $transaction->tag])
+ @endif
+ </div>
+ <div class="row__column {{ get_class($transaction) == 'App\Earning' ? 'color-green' : 'color-red' }}">{!! $currency !!} {{ $transaction->formatted_amount }}</div>
+ <div class="row__column text-right">{{ $transaction->happened_on }}</div>
+ </div>
+ @endforeach
+ </div>
+ @endforeach
+ </div>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -18,6 +18,11 @@ Route::group(['middleware' => ['auth']], function () {
Route::get('/transactions/create', 'TransactionController@create')->name('transactions.create');
+ Route::name('transactions.')->group(function () {
+ Route::get('/transactions', 'TransactionController@index')->name('index');
+ Route::get('/transactions/create', 'TransactionController@create')->name('create');
+ });
+
Route::name('earnings.')->group(function () {
Route::get('/earnings', 'EarningController@index')->name('index');
Route::get('/earnings/create', 'EarningController@create')->name('create');

Add index function to TransactionController