Total Complexity | 2 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class CreateLikeableTables extends Migration |
||
11 | { |
||
12 | /** |
||
13 | * Run the migrations. |
||
14 | * |
||
15 | * @return void |
||
16 | */ |
||
17 | public function up() |
||
18 | { |
||
19 | Schema::create('likes', function(Blueprint $table) { |
||
20 | $table->id(); |
||
21 | $table->morphs('likeable'); |
||
22 | $table->unsignedBigInteger('user_id')->index(); |
||
23 | $table->enum('type_id', [ |
||
24 | 'like', |
||
25 | 'dislike', |
||
26 | ])->default('like'); |
||
27 | $table->timestamps(); |
||
28 | |||
29 | $table->unique([ |
||
30 | 'likeable_id', |
||
31 | 'likeable_type', |
||
32 | 'user_id', |
||
33 | ], 'like_user_unique'); |
||
34 | |||
35 | }); |
||
36 | |||
37 | Schema::create('like_counters', function(Blueprint $table) { |
||
38 | $table->id(); |
||
39 | $table->morphs('likeable'); |
||
40 | $table->enum('type_id', [ |
||
41 | 'like', |
||
42 | 'dislike', |
||
43 | ])->default('like'); |
||
44 | $table->unsignedBigInteger('count')->default(0); |
||
45 | $table->timestamps(); |
||
46 | |||
47 | $table->unique([ |
||
48 | 'likeable_id', |
||
49 | 'likeable_type', |
||
50 | 'type_id', |
||
51 | ], 'like_counter_unique'); |
||
52 | }); |
||
53 | |||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Reverse the migrations. |
||
58 | * |
||
59 | * @return void |
||
60 | */ |
||
61 | public function down() |
||
62 | { |
||
63 | Schema::drop('likes'); |
||
64 | Schema::drop('like_counters'); |
||
65 | } |
||
67 |