Есть таблица с юзерами:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Таблица с серверами:
Schema::create('servers', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->string('ip')->unique();
$table->string('login');
$table->string('pass');
$table->string('country')->nullable();
$table->string('image_url')->nullable();
$table->double('ping')->nullable();
$table->integer('personalPrice');
$table->integer('sharedPrice');
$table->integer('uptime')->default(100);
$table->timestamps();
});
Промежуточная таблица server-user(многие-ко-многим):
Schema::create('server_user', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->integer('user_id')->unsigned()->onDelete('cascade');
$table->integer('server_id')->unsigned()->onDelete('cascade');
$table->timestamps();
});
Таблица купленных серверов:
Schema::create('purchased_servers', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->date('purchase_date')->nullable();
$table->date('payment_date')->nullable();
$table->boolean('status');
$table->integer('server_id')->unsigned();
$table->foreign('server_id')->references('id')->on('server_user')->onDelete('cascade');
$table->timestamps();
});
Суть:
юзер может купить несколько серверов. Как определить связи в моделях?