Package Data | |
---|---|
Maintainer Username: | mintbridge |
Maintainer Contact: | paul.dixon@mintbridge.co.uk (Paul Dixon) |
Package Create Date: | 2016-02-20 |
Package Last Update: | 2018-10-15 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-26 15:18:44 |
Package Statistics | |
---|---|
Total Downloads: | 369 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 1 |
Total Forks: | 2 |
Total Open Issues: | 1 |
Laravel 5 package that allows users to favourite eloquent models.
This package can be installed through Composer.
composer require mintbridge/eloquent-favourites
Once installed add the service provider and facade to your app config
// config/app.php
'providers' => [
'...',
'Mintbridge\EloquentFavourites\FavouritesServiceProvider',
];
'aliases' => [
'...',
'Favourites' => 'Mintbridge\EloquentFavourites\FavouritesFacade',
];
You'll also need to publish and run the migration in order to create the database table.
php artisan vendor:publish --provider="Mintbridge\EloquentFavourites\FavouritesServiceProvider" --tag="config"
php artisan vendor:publish --provider="Mintbridge\EloquentFavourites\FavouritesServiceProvider" --tag="migrations"
php artisan migrate
The configuration will be written to config/eloquent-favourites.php
. The options have sensible defaults but you should change the user model to match the one used in your application.
This package will allow your users to favourite models used in your application. To do so the models that you would like to favouritable must use the Favouritable
trait and implement FavouritableInterface
.
use Mintbridge\EloquentFavourites\Favouritable;
use Mintbridge\EloquentFavourites\FavouritableInterface;
class Article extends Eloquent implements FavouritableInterface {
use Favouritable;
...
}
Models can then be favourited, un-favourited or toggled using by using the FavouritesManager
or more easily with the favourites facade:
$article = Article::find(1);
// add article as a favourite
Favourites::add($article);
// remove article from by a favourite
Favourites::remove($article);
// toggle article as being a favourite
Favourites::toggle($article);
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.