DEV Community

Discussion on: How to implement a simple like system with Laravel

Collapse
 
mateator profile image
mateator • Edited

Ty man, i have been stuck for weeks because of that, it wasnt working until you wrote to took out the ->exists();

same thing to delete, the result is:
$likeable->likes()->whereHas('user', function(Builder $query) {
$query->whereId($this->id);
})->delete();

Also, if someone implements this, dont forget to add this in Likes.php
use Illuminate\Database\Eloquent\Builder;

Collapse
 
bdelespierre profile image
Benjamin Delespierre

Yeah I removed the Builder typehint, it wasn't very helpful anyway.