Skip to content

Commit d7ebed1

Browse files
committed
wip
1 parent c2306ac commit d7ebed1

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

app/Helpers/HasLikes.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function likedBy(User $user)
2222

2323
public function dislikedBy(User $user)
2424
{
25-
optional($this->likes()->where('user_id', $user->id)->get()->first())->delete();
25+
optional($this->likes()->where('user_id', $user->id)->first())->delete();
2626
}
2727

2828
public function likes(): MorphMany
@@ -32,10 +32,6 @@ public function likes(): MorphMany
3232

3333
public function isLikedBy(User $user): bool
3434
{
35-
if ($user == null) {
36-
return false;
37-
}
38-
3935
return $this->likes()->where('user_id', $user->id)->exists();
4036
}
4137

database/migrations/2017_12_03_111900_create_likes_table.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
class CreateLikesTable extends Migration
88
{
9-
/**
10-
* Run the migrations.
11-
*
12-
* @return void
13-
*/
149
public function up()
1510
{
1611
Schema::create('likes', function (Blueprint $table) {
@@ -20,15 +15,12 @@ public function up()
2015
$table->string('likeable_type');
2116
$table->timestamps();
2217
});
23-
}
2418

25-
/**
26-
* Reverse the migrations.
27-
*
28-
* @return void
29-
*/
30-
public function down()
31-
{
32-
Schema::dropIfExists('likes');
19+
Schema::table('subscriptions', function (Blueprint $table) {
20+
$table->index(['user_id', 'uuid']);
21+
$table->foreign('user_id')
22+
->references('id')->on('users')
23+
->onDelete('CASCADE');
24+
});
3325
}
3426
}

0 commit comments

Comments
 (0)