ChristianKuri / laravel-favorite

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

General Question - Toggle Favorite icon with count in view #7

Closed ghost closed 6 years ago

ghost commented 6 years ago

I have installed your package and added $user = User::first(); $user->toggleFavorite($article); in the articleshow method.

How to create a icon in the view blade file so that when a user clicks on it the logged in user is added to favorites count of the post and when the user clicks it again, he is removed from the favorites count of that article.

I see that there are $user->addFavorite($article); and $user->removeFavorite($article); But how to use them in the controller to gain the functionality i mentioned

ghost commented 6 years ago

Got it solved on Stackoverflow. Here is the link

Though it would be helpful to someone who uses this package