1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/laravel-follow |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Illuminate\Database\Schema\Blueprint; |
13
|
|
|
use Illuminate\Database\Migrations\Migration; |
14
|
|
|
|
15
|
|
|
class CreateLaravelFollowTables extends Migration |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Run the migrations. |
19
|
|
|
*/ |
20
|
|
|
public function up() |
21
|
|
|
{ |
22
|
|
|
Schema::create( |
23
|
|
|
\Illuminate\Support\Facades\Config::get('follow.followable_table', 'followables'), function (Blueprint $table) { |
24
|
|
|
$userForeignKey = \Illuminate\Support\Facades\Config::get('follow.users_table_foreign_key', 'person_code'); |
25
|
|
|
|
26
|
|
|
// // Laravel 5.8 session user is unsignedBigInteger |
27
|
|
|
// // https://github.com/laravel/framework/pull/28206/files |
28
|
|
|
// if ((float) app()->version() >= 5.8) { |
29
|
|
|
// $table->unsignedBigInteger($userForeignKey); |
30
|
|
|
// } else { |
31
|
|
|
// $table->unsignedInteger($userForeignKey); |
32
|
|
|
// } |
33
|
|
|
$table->string($userForeignKey); |
34
|
|
|
|
35
|
|
|
$table->string('followable_id'); |
36
|
|
|
$table->string('followable_type')->index(); |
37
|
|
|
$table->string('relation')->default('follow')->comment('follow/like/subscribe/favorite/upvote/downvote'); |
38
|
|
|
$table->softDeletes(); |
39
|
|
|
$table->timestamps(); |
40
|
|
|
|
41
|
|
|
// $table->foreign($userForeignKey) |
42
|
|
|
// ->references(\Illuminate\Support\Facades\Config::get('follow.users_table_primary_key', 'id')) |
43
|
|
|
// ->on(\Illuminate\Support\Facades\Config::get('follow.users_table_name', 'users')) |
44
|
|
|
// ->onUpdate('cascade') |
45
|
|
|
// ->onDelete('cascade'); |
46
|
|
|
} |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Reverse the migrations. |
52
|
|
|
*/ |
53
|
|
|
public function down() |
54
|
|
|
{ |
55
|
|
|
Schema::table( |
56
|
|
|
\Illuminate\Support\Facades\Config::get('follow.followable_table', 'followables'), function ($table) { |
57
|
|
|
$table->dropForeign(\Illuminate\Support\Facades\Config::get('follow.followable_table', 'followables').'_user_id_foreign'); |
58
|
|
|
} |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
Schema::drop(\Illuminate\Support\Facades\Config::get('follow.followable_table', 'followables')); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|