added setting user many to many relationship

This commit is contained in:
Chris 2018-10-12 15:10:40 +01:00
parent e86e681c53
commit 30c3079a90
3 changed files with 52 additions and 0 deletions

View file

@ -218,4 +218,13 @@ class Setting extends Model
} }
return $output; return $output;
} }
/**
* The users that belong to the setting.
*/
public function users()
{
return $this->belongsToMany('App\User');
}
} }

View file

@ -35,4 +35,12 @@ class User extends Authenticatable
return $this->hasMany('App\Item'); return $this->hasMany('App\Item');
} }
/**
* The settings that belong to the user.
*/
public function settings()
{
return $this->belongsToMany('App\Setting');
}
} }

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSettingUserPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('setting_user', function (Blueprint $table) {
$table->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');
}
}