ufutx/laravel-favorite
Larablocks Analysis
ufutx/laravel-favorite works with Laravel 5 (latest release v1.3.3, Nov 25, 2017), which reached end of life: no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: Nov 25, 2017)
- 0 downloads a month (needs 10,000)
- 6 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Nov 25, 2017.
- No releases in the last 12 months.
- First released: Dec 21, 2016.
- 1 open issue on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Dec 2, 2026.
| Install | |
|---|---|
composer require ufutx/laravel-favorite |
|
| Latest Version: | v1.3.3 |
| PHP: | >=5.5.9 |
| Laravel: | 5 |
| License: | MIT |
| Last Updated: | Nov 25, 2017 |
| Links: | GitHub · Packagist |
Laravel Favorite (Laravel 5 Package, forked from Ufutx/laravel-favorite)
Allows Laravel Eloquent models to implement a 'favorite' or 'remember' or 'follow' feature.
Index
Installation
- Install the package via Composer
$ composer require ufutx/laravel-favorite
- Update
config/app.phpby adding an entry for the service provider.
'providers' => [
// ...
Ufutx\LaravelFavorite\FavoriteServiceProvider::class,
];
- Migrate the database from the command line:
php artisan migrate
Models
Your User model should import the Traits/Favoriteability.php trait and use it, that trait allows the user to favorite the models.
(see an example below):
use Ufutx\LaravelFavorite\Traits\Favoriteability;
class User extends Authenticatable
{
use Favoriteability;
}
Your models should import the Traits/Favoriteable.php trait and use it, that trait have the methods that you'll use to allow the model be favoriteable.
In all the examples I will use the Post model as the model that is 'Favoriteable', thats for example propuses only.
(see an example below):
use Ufutx\LaravelFavorite\Traits\Favoriteable;
class Post extends Model
{
use Favoriteable;
}
That's it ... your model is now "favoriteable"! Now the User can favorite models that have the favoriteable trait.
Usage
The models can be favorited with and without an authenticated user (see examples below):
Add to favorites and remove from favorites:
If no param is passed in the favorite method, then the model will asume the auth user.
$post = Post::find(1);
$post->addFavorite(); // auth user added to favorites this post
$post->removeFavorite(); // auth user removed from favorites this post
$post->toggleFavorite(); // auth user toggles the favorite status from this post
If a param is passed in the favorite method, then the model will asume the user with that id.
$post = Post::find(1);
$post->addFavorite(5); // user with that id added to favorites this post
$post->removeFavorite(5); // user with that id removed from favorites this post
$post->toggleFavorite(5); // user with that id toggles the favorite status from this post
The user model can also add to favorites and remove from favrites:
$user = User::first();
$post = Post::first();
$user->addFavorite($post); // The user added to favorites this post
$user->removeFavorite($post); // The user removed from favorites this post
$user->toggleFavorite($post); // The user toggles the favorite status from this post
Return the favorite objects for the user:
A user can return the objects he marked as favorite.
You just need to pass the class in the favorite() method in the User model.
$user = Auth::user();
$user->favorite(Post::class); // returns a collection with the Posts the User marked as favorite
Return the favorites count from an object:
You can return the favorites count from an object, you just need to return the favoritesCount attribute from the model
$post = Post::find(1);
$post->favoritesCount; // returns the number of users that have marked as favorite this object.
Return the users who marked this object as favorite
You can return the users who marked this object, you just need to call the favoritedBy() method in the object
$post = Post::find(1);
$post->favoritedBy(); // returns a collection with the Users that marked the post as favorite.
Testing
The package have integrated testing, so everytime you make a pull request your code will be tested.
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributions
Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.
Pull Requests
-
PSR-2 Coding Standard - Check the code style with
$ composer check-styleand fix it with$ composer fix-style. -
Add tests! - Your patch won't be accepted if it doesn't have tests.
-
Document any change in behaviour - Make sure the
README.mdand any other relevant documentation are kept up-to-date. -
Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option.
-
Create feature branches - Don't ask us to pull from your master branch.
-
One pull request per feature - If you want to do more than one thing, send multiple pull requests.
-
Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
Security
Please report any issue you find in the issues page.
Pull requests are welcome.
Credits
License
The MIT License (MIT). Please see License File for more information.
Alternatives to ufutx/laravel-favorite
Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent model...
Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'f...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.3.3 | >=5.5.9 | >=5.2 | MIT | |
| v1.3.2 | >=5.5.9 | >=5.2 | MIT | |
| v1.3.1 | >=5.5.9 | >=5.2 | MIT | |
| v1.3.0 | >=5.6.4 | >=5.3 | MIT | |
| v1.2.0 | >=5.6.4 | >=5.3 | MIT | |
| v1.1.0 | >=5.6.4 | >=5.3 | MIT | |
| v1.0.0 | >=5.6.4 | >=5.0 | MIT |