diff --git a/app/Setting.php b/app/Setting.php index 706e1eb7..b981d0d2 100644 --- a/app/Setting.php +++ b/app/Setting.php @@ -218,4 +218,13 @@ class Setting extends Model } return $output; } + + /** + * The users that belong to the setting. + */ + public function users() + { + return $this->belongsToMany('App\User'); + } + } diff --git a/app/User.php b/app/User.php index 7c7d7ea1..fb9f8fdd 100644 --- a/app/User.php +++ b/app/User.php @@ -35,4 +35,12 @@ class User extends Authenticatable return $this->hasMany('App\Item'); } + /** + * The settings that belong to the user. + */ + public function settings() + { + return $this->belongsToMany('App\Setting'); + } + } diff --git a/database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php b/database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php new file mode 100644 index 00000000..94cd1cd0 --- /dev/null +++ b/database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php @@ -0,0 +1,35 @@ +integer('setting_id')->unsigned()->index(); + $table->foreign('setting_id')->references('id')->on('settings')->onDelete('cascade'); + $table->integer('user_id')->unsigned()->index(); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->primary(['setting_id', 'user_id']); + $table->string('value')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('setting_user'); + } +}