ChristianKuri / laravel-favorite

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

Bugfix/check favoriteable isset #16

Closed jedsonmelo closed 4 years ago

jedsonmelo commented 4 years ago

Description

Check favoriteable isset before put on favorites stack.

Motivation and context

When a favorite user is a specific model and that model is deleted it is returned in the favorite() method this causes an exception when trying to access id. Exception below:

`ErrorException: Trying to get property 'id' of non-object

/home/jedson/develop/contribuitions/laravel-favorite/src/Traits/Favoriteability.php:38 /home/jedson/develop/contribuitions/laravel-favorite/vendor/laravel/framework/src/Illuminate/Support/Collection.php:816 /home/jedson/develop/contribuitions/laravel-favorite/src/Traits/Favoriteability.php:40 /home/jedson/develop/contribuitions/laravel-favorite/tests/FavoriteModelTest.php:238`

How has this been tested?

Favorite two articles with user and delete one of them. Checks if the return number in favorite () is equal to one.

Types of changes

What types of changes does your code introduce?

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests and code style pass.