ChristianKuri / laravel-favorite

Allows Laravel Eloquent models to implement a 'favorite', 'like', 'remember' and 'follow' features.
MIT License
226 stars 48 forks source link

How to check in view file if the user has liked the post? #26

Open webfuelcode opened 3 years ago

webfuelcode commented 3 years ago

I am trying to show the different colors for liked and non-liked users on the view file.

I am using laravel 7, how to use $post->isFavorited() on laravel view file, with if-else statement...

Ahmad-Fathy commented 2 years ago

You can do it like this

<span class="{{ $post->isFavorited() ? 'bg-yellow-500' : 'bg-gray-500'  }}">⭐</span>

but it gives me eager loading issue https://github.com/ChristianKuri/laravel-favorite/issues/32