DEV Community

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

Collapse
 
devkitshow profile image
devkitshow • Edited

Hello! There's also a problem in LikesRequest

'id' => [
                "required",
                function ($attribute, $value, $fail) {
                    $class = $this->getClass($value);

                    if (! $class::where('id', $value)->exists()) {
                        $fail($value." is not present in database");
                    }
                },
            ],
Enter fullscreen mode Exit fullscreen mode

this would give you an error due to getClass($value) is trying to get class of numeric id.
So it should probably be like

$class = $this->getClass($this->input('likeable'));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bdelespierre profile image
Benjamin Delespierre

Thanks for pointing this out. I'm fixing the article as we speak to take your feedback into account. Stay tuned!

Collapse
 
bdelespierre profile image
Benjamin Delespierre

Should be fixed now. What do you think?