Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tobischulz/laravel-favoritable
Adds an easy way to make every model favoritable
https://github.com/tobischulz/laravel-favoritable
Last synced: about 1 month ago
JSON representation
Adds an easy way to make every model favoritable
- Host: GitHub
- URL: https://github.com/tobischulz/laravel-favoritable
- Owner: tobischulz
- Created: 2020-07-14T10:48:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-12T13:05:05.000Z (9 months ago)
- Last Synced: 2024-09-18T02:20:36.361Z (about 2 months ago)
- Language: PHP
- Size: 335 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Favoritable
[![Latest Version on Packagist](https://img.shields.io/packagist/v/tobischulz/laravel-favoritable.svg?style=flat-square)](https://packagist.org/packages/tobischulz/laravel-favoritable)
[![Total Downloads](https://img.shields.io/packagist/dt/tobischulz/laravel-favoritable.svg?style=flat-square)](https://packagist.org/packages/tobischulz/laravel-favoritable)Adds an easy way to make every model favoritable.
## Installation
You can install the package via composer:
```bash
composer require tobischulz/laravel-favoritable
```Publish all required assets:
```bash
php artisan vendor:publish --provider=TobiSchulz\Favoritable\FavoritableServiceProvider
```Migrate your database:
```bash
php artisan migrate
```## Preparation
Add trait to eloquent model that you like to be favoritable.
```php
addFavorite(); // adds this post to favorites to current user
$post->removeFavorite(); // remove this post from favorites
$post->toggleFavorite(); // toggle this post as favorite
$post->isFavorited(); // returns boolean for this post favorite state$post = Post::find(1);
$user = User::find(2);$post->addFavorite($user); // adds favorite for this post and a specific user.
/**
* API for HasFavorites
*/
$user = User::find(1);$user->favorites(Post::class); // returns collection of Post::class favorites
```
### Testing
wip
### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Tobias Schulz](https://github.com/:tobischulz)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.