Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.