Deprecate index views and routes for earnings and spendings
MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -17,18 +17,6 @@ class EarningController extends Controller {
];
}
- public function index() {
- $user = Auth::user();
-
- $earnings = session('space')
- ->earnings()
- ->orderBy('happened_on', 'DESC')
- ->orderBy('created_at', 'DESC')
- ->get();
-
- return view('earnings.index', compact('earnings'));
- }
-
public function create() {
return view('earnings.create');
}
@@ -90,6 +78,6 @@ class EarningController extends Controller {
$earning->restore();
- return redirect()->route('earnings.index');
+ return redirect()->route('transactions.index');
}
}

MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -10,35 +10,6 @@ use App\Models\Tag;
use Auth;
class SpendingController extends Controller {
- public function index(Request $request) {
- $filter = false;
-
- $spendingsByMonth = [];
-
- for ($month = 12; $month >= 1; $month --) {
- $query = session('space')
- ->spendings()
- ->whereYear('happened_on', date('Y'))
- ->whereMonth('happened_on', $month);
-
-
- if ($import_id = $request->get('filter_by_import')) {
- $filter = 'import';
-
- $query->where('import_id', $import_id);
- }
-
- $spendingsThisMonth = $query->orderBy('happened_on', 'DESC')
- ->get();
-
- if (count($spendingsThisMonth)) {
- $spendingsByMonth[$month] = $spendingsThisMonth;
- }
- }
-
- return view('spendings.index', compact('filter', 'spendingsByMonth'));
- }
-
public function create() {
$tags = session('space')->tags()->orderBy('created_at', 'DESC')->get();
@@ -113,6 +84,6 @@ class SpendingController extends Controller {
$spending->restore();
- return redirect()->route('spendings.index');
+ return redirect()->route('transactions.index');
}
}

DELETE
resources/views/earnings/index.blade.php
-@extends('layout')
-
-@section('title', __('models.earnings'))
-
-@section('body')
- <div class="wrapper my-3">
- <div class="row">
- <div class="row__column row__column--middle">
- <h2>{{ __('models.earnings') }}</h2>
- </div>
- <div class="row__column row__column--compact row__column--middle">
- <a href="/earnings/create" class="button">{{ __('actions.create') }} {{ __('models.earning') }}</a>
- </div>
- </div>
- @if (session('restorableEarning'))
- <div class="mt-3">You've successfully deleted that earning</div>
- <form method="POST" action="/earnings/{{ session('restorableEarning') }}/restore" class="mt-05">
- {{ csrf_field() }}
- <button class="button link">You can still recover it</button>
- </form>
- @endif
- <div class="box mt-3">
- @if (count($earnings))
- @foreach ($earnings as $earning)
- <div class="box__section row">
- <div class="row__column">
- <div class="color-dark">{{ $earning->description }}</div>
- <div class="mt-1" style="font-size: 14px; font-weight: 600;">{{ $earning->formatted_happened_on }}</div>
- </div>
- <div class="row__column row__column--middle color-dark">{!! $currency !!} {{ $earning->formatted_amount }}</div>
- <div class="row__column row__column--middle row row--right">
- <div class="row__column row__column--compact">
- <a href="/earnings/{{ $earning->id }}/edit">
- <i class="fas fa-pencil"></i>
- </a>
- </div>
- <div class="row__column row__column--compact ml-2">
- <form method="POST" action="/earnings/{{ $earning->id }}">
- {{ method_field('DELETE') }}
- {{ csrf_field() }}
- <button class="button link">
- <i class="fas fa-trash-alt"></i>
- </button>
- </form>
- </div>
- </div>
- </div>
- @endforeach
- @else
- @include('partials.empty_state', ['payload' => 'earnings'])
- @endif
- </div>
- </div>
-@endsection

DELETE
resources/views/spendings/index.blade.php
-@extends('layout')
-
-@section('title', __('models.spendings'))
-
-@section('body')
- <div class="wrapper my-3">
- <div class="row">
- <div class="row__column row__column--middle">
- <h2>{{ __('models.spendings') }}</h2>
- @if ($filter)
- <div class="mt-1">Only showing spendings for selected {{ strtolower(__('models.' . $filter)) }}</div>
- @endif
- </div>
- @if (!$filter)
- <div class="row__column row__column--compact row__column--middle">
- <a href="/spendings/create" class="button">{{ __('actions.create') }} {{ __('models.spending') }}</a>
- </div>
- @endif
- </div>
- @if (session('restorableSpending'))
- <div class="mt-3">You've successfully deleted that spending</div>
- <form method="POST" action="/spendings/{{ session('restorableSpending') }}/restore" class="mt-05">
- {{ csrf_field() }}
- <button class="button link">You can still recover it</button>
- </form>
- @endif
- @if (count($spendingsByMonth))
- @foreach ($spendingsByMonth as $index => $spendings)
- @if (count($spendings))
- <h3 class="mt-3 mb-2">{{ __('calendar.months.' . $index) }}</h3>
- <div class="box">
- @foreach ($spendings as $spending)
- <div class="box__section row">
- <div class="row__column">
- <div class="color-dark">{{ $spending->description }}</div>
- <div class="mt-1" style="font-size: 14px; font-weight: 600;">{{ $spending->formatted_happened_on }}</div>
- </div>
- <div class="row__column row__column--middle">
- @if ($spending->tag)
- @include('partials.tag', ['payload' => $spending->tag])
- @endif
- </div>
- <div class="row__column row__column--middle color-dark">{!! $currency !!} {{ $spending->formatted_amount }}</div>
- <div class="row__column row__column--middle row__column--compact">
- <form method="POST" action="/spendings/{{ $spending->id }}">
- {{ method_field('DELETE') }}
- {{ csrf_field() }}
- <button class="button link">
- <i class="fas fa-trash-alt"></i>
- </button>
- </form>
- </div>
- </div>
- @endforeach
- </div>
- @endif
- @endforeach
- @else
- <div class="box mt-3">
- @include('partials.empty_state', ['payload' => 'spendings'])
- </div>
- @endif
- </div>
-@endsection

MODIFY
routes/web.php
routes/web.php
@@ -24,7 +24,6 @@ Route::group(['middleware' => ['auth']], function () {
});
Route::name('earnings.')->group(function () {
- Route::get('/earnings', 'EarningController@index')->name('index');
Route::get('/earnings/create', 'EarningController@create')->name('create');
Route::post('/earnings', 'EarningController@store');
Route::get('/earnings/{earning}/edit', 'EarningController@edit')->name('edit');
@@ -34,7 +33,6 @@ Route::group(['middleware' => ['auth']], function () {
});
Route::name('spendings.')->group(function () {
- Route::get('/spendings', 'SpendingController@index')->name('index');
Route::get('/spendings/create', 'SpendingController@create')->name('create');
Route::post('/spendings', 'SpendingController@store');
Route::get('/spendings/{spending}/edit', 'SpendingController@edit')->name('edit');

Deprecate index views and routes for earnings and spendings