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(config('follow.followable_table', 'followables'), function (Blueprint $table) { |
||
23 | $userForeignKey = config('follow.users_table_foreign_key', 'user_id'); |
||
24 | |||
25 | // Laravel 5.8 session user is unsignedBigInteger |
||
26 | // https://github.com/laravel/framework/pull/28206/files |
||
27 | if ((float) app()->version() >= 5.8) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
28 | $table->unsignedBigInteger($userForeignKey); |
||
29 | } else { |
||
30 | $table->unsignedInteger($userForeignKey); |
||
31 | } |
||
32 | |||
33 | $table->unsignedInteger('followable_id'); |
||
34 | $table->string('followable_type')->index(); |
||
35 | $table->string('relation')->default('follow')->comment('follow/like/subscribe/favorite/upvote/downvote'); |
||
36 | $table->softDeletes(); |
||
37 | $table->timestamps(); |
||
38 | |||
39 | $table->foreign($userForeignKey) |
||
40 | ->references(config('follow.users_table_primary_key', 'id')) |
||
41 | ->on(config('follow.users_table_name', 'users')) |
||
42 | ->onUpdate('cascade') |
||
43 | ->onDelete('cascade'); |
||
44 | }); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Reverse the migrations. |
||
49 | */ |
||
50 | public function down() |
||
51 | { |
||
52 | Schema::table(config('follow.followable_table', 'followables'), function ($table) { |
||
53 | $table->dropForeign(config('follow.followable_table', 'followables').'_user_id_foreign'); |
||
54 | }); |
||
55 | |||
56 | Schema::drop(config('follow.followable_table', 'followables')); |
||
57 | } |
||
58 | } |
||
59 |