Add Recurring model and it's migration
ADD
app/Recurring.php
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class Recurring extends Model {
+ use SoftDeletes;
+
+ protected $dates = ['deleted_at'];
+
+ public function spendings() {
+ return $this->hasMany(Spending::class);
+ }
+}

MODIFY
app/Spending.php
app/Spending.php
@@ -22,6 +22,10 @@ class Spending extends Model {
}
// Relations
+ public function recurring() {
+ return $this->belongsTo(Recurring::class);
+ }
+
public function tag() {
return $this->belongsTo('App\Tag');
}

MODIFY
database/migrations/2017_07_20_000000_create_spendings_table.php
database/migrations/2017_07_20_000000_create_spendings_table.php
@@ -9,6 +9,7 @@ class CreateSpendingsTable extends Migration {
Schema::create('spendings', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
+ $table->integer('recurring_id')->unsigned()->nullable();
$table->integer('tag_id')->unsigned()->nullable();
$table->date('happened_on');
$table->string('description');

ADD
database/migrations/2018_09_13_112448_create_recurrings_table.php
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateRecurringsTable extends Migration {
+ public function up() {
+ Schema::create('recurrings', function (Blueprint $table) {
+ $table->increments('id');
+ $table->integer('user_id')->unsigned();
+ $table->string('type');
+ $table->string('day');
+ $table->date('starts_on');
+ $table->date('ends_on');
+ $table->date('last_used_on');
+ $table->integer('tag_id')->unsigned()->nullable();
+ $table->string('description');
+ $table->integer('amount');
+ $table->timestamps();
+ $table->softDeletes();
+ });
+ }
+
+ public function down() {
+ Schema::dropIfExists('recurrings');
+ }
+}

Add Recurring model and it's migration