Change user_id field in spendings table to space_id
MODIFY
app/Space.php
app/Space.php
@@ -14,4 +14,8 @@ class Space extends Model {
public function tags() {
return $this->hasMany(Tag::class);
}
+
+ public function spendings() {
+ return $this->hasMany(Spending::class);
+ }
}

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

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

Change user_id field in spendings table to space_id