-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathcreate_acquaintances_interactions_table.php
executable file
·50 lines (41 loc) · 1.71 KB
/
create_acquaintances_interactions_table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Multicaret\Acquaintances\Interaction;
class CreateAcquaintancesInteractionsTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create(config('acquaintances.tables.interactions', 'interactions'), function (Blueprint $table) {
$table->id();
$userModel = Interaction::getUserModelName();
$userModel = (new $userModel);
$userIdFkColumnName = config('acquaintances.tables.interactions_user_id_fk_column_name', 'user_id');
$userIdFkType = config('acquaintances.tables.interactions_user_id_fk_column_type');
$table->{$userIdFkType}($userIdFkColumnName)->index();
$table->morphs('subject');
$table->string('relation')->default('follow')->comment('follow/like/subscribe/favorite/upvote/downvote');
$table->double('relation_value')->nullable();
$table->string('relation_type')->nullable();
$table->timestamps();
$table->foreign($userIdFkColumnName)
->references($userModel->getKeyName())
->on($userModel->getTable())
->onUpdate('cascade')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::table(config('acquaintances.tables.interactions', 'interactions'), function ($table) {
$table->dropForeign(config('acquaintances.tables.interactions', 'interactions').'_user_id_foreign');
});
Schema::drop(config('acquaintances.tables.interactions', 'interactions'));
}
}