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

MODIFY
app/User.php
app/User.php
@@ -20,10 +20,6 @@ class User extends Authenticatable {
return $this->belongsToMany(Space::class, 'user_space');
}
- public function earnings() {
- return $this->hasMany(Earning::class);
- }
-
public function recurrings() {
return $this->hasMany(Recurring::class);
}

MODIFY
database/migrations/2017_07_21_000000_create_earnings_table.php
database/migrations/2017_07_21_000000_create_earnings_table.php
@@ -8,7 +8,7 @@ class CreateEarningsTable extends Migration {
public function up() {
Schema::create('earnings', function (Blueprint $table) {
$table->increments('id');
- $table->integer('user_id')->unsigned();
+ $table->unsignedInteger('space_id');
$table->date('happened_on');
$table->string('description');
$table->integer('amount');

Change user_id field in earnings table to space_id