Add RecurringController
ADD
app/Http/Controllers/RecurringController.php
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use Auth;
+
+class RecurringController extends Controller {
+ public function index() {
+ $user = Auth::user();
+
+ return view('recurrings.index', [
+ 'currency' => $user->currency,
+ 'recurrings' => $user->recurrings()->orderBy('created_at', 'DESC')->get()
+ ]);
+ }
+}

MODIFY
app/Recurring.php
app/Recurring.php
@@ -10,7 +10,25 @@ class Recurring extends Model {
protected $dates = ['deleted_at'];
+ // Accessors
+ public function getDueDaysAttribute() {
+ if ($this->starts_on <= date('Y-m-d') && $this->ends_on >= date('Y-m-d')) {
+ if (date('j') > $this->day) {
+ return date('t') - date('j') + $this->day;
+ }
+
+ return $this->day - date('j');
+ }
+
+ return 0;
+ }
+
+ // Relations
public function spendings() {
return $this->hasMany(Spending::class);
}
+
+ public function tag() {
+ return $this->belongsTo(Tag::class);
+ }
}

MODIFY
app/User.php
app/User.php
@@ -30,6 +30,10 @@ class User extends Authenticatable {
return $this->hasMany(Spending::class);
}
+ public function recurrings() {
+ return $this->hasMany(Recurring::class);
+ }
+
public function tags() {
return $this->hasMany(Tag::class);
}

MODIFY
resources/lang/en/general.php
resources/lang/en/general.php
@@ -19,5 +19,7 @@ return [
'email' => 'E-mail',
'verify' => 'Verify',
'password' => 'Password',
- 'language' => 'Language'
+ 'language' => 'Language',
+
+ 'recurrings' => 'Recurrings'
];

MODIFY
resources/lang/nl/general.php
resources/lang/nl/general.php
@@ -19,5 +19,7 @@ return [
'email' => 'E-mail',
'verify' => 'Controleer',
'password' => 'Wachtwoord',
- 'language' => 'Taal'
+ 'language' => 'Taal',
+
+ 'recurrings' => 'Terugkerenden'
];

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
<li>
<a href="/dashboard" {!! (Request::path() == 'dashboard') ? 'class="active"' : '' !!}><i class="fas fa-home fa-sm mr-05"></i> @lang('general.dashboard')</a>
</li>
+ <li>
+ <a href="/recurrings" {!! (Request::path() == 'recurrings') ? 'class="active"' : '' !!}><i class="fas fa-recycle fa-sm mr-05"></i> {{ __('general.recurrings') }}</a>
+ </li>
</ul>
<ul class="navigation__menu">
<li class="dropdown">

ADD
resources/views/recurrings/index.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="wrapper my-4">
+ <div class="color-dark mb-2">{{ __('general.recurrings') }}</div>
+ <div class="box">
+ @foreach ($recurrings as $recurring)
+ <div class="box__section row">
+ <div class="row__column">
+ <div class="color-dark">{{ $recurring->description }}</div>
+ <div class="row mt-1">
+ <div class="row__column row__column--compact" style="font-size: 14px; font-weight: 600;">{!! $currency->symbol !!} {{ number_format($recurring->amount / 100, 2) }}</div>
+ @if ($recurring->due_days)
+ <div class="row__column row__column--compact ml-2" style="font-size: 14px; font-weight: 600;"><i class="far fa-clock"></i> Due in {{ $recurring->due_days }} days</div>
+ @endif
+ </div>
+ </div>
+ <div class="row__column row__column--middle">
+ @if ($recurring->due_days)
+ <span style="border-radius: 5px; background: #D8F9E8; color: #51B07F; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-check fa-xs"></i> Active</span>
+ @else
+ <span style="border-radius: 5px; background: #FFE7EC; color: #F25C68; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-times fa-xs"></i> Inactive</span>
+ @endif
+ </div>
+ <div class="row__column row__column--middle">
+ @if ($recurring->tag)
+ <span style="border-radius: 5px; background: #DEEAFE; color: #618DD7; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-tag fa-xs"></i> {{ $recurring->tag->name }}</span>
+ @endif
+ </div>
+ </div>
+ @endforeach
+ </div>
+ </div>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -21,6 +21,8 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/spendings', 'SpendingsController@store');
Route::delete('/spendings/{spending}', 'SpendingsController@destroy')->middleware('can:delete,spending');
+ Route::resource('/recurrings', 'RecurringController')->only(['index']);
+
Route::get('/tags', 'TagsController@index')->name('tags');
Route::get('/tags/create', 'TagsController@create')->name('tags.create');
Route::post('/tags', 'TagsController@store');

Add RecurringController