Browse Source

added setting user many to many relationship

pull/260/head
Chris 6 years ago
parent
commit
30c3079a90
  1. 9
      app/Setting.php
  2. 8
      app/User.php
  3. 35
      database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php

9
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');
}
}

8
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');
}
}

35
database/migrations/2018_10_12_140451_create_setting_user_pivot_table.php

@ -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');
}
}
Loading…
Cancel
Save