LaravelPackages.net
Acme Inc.
Toggle sidebar
mintbridge/eloquent-sentiment

An eloquent package for adding sentiment to eloquent models.

256
1
0.0.1
About mintbridge/eloquent-sentiment

mintbridge/eloquent-sentiment is a Laravel package for an eloquent package for adding sentiment to eloquent models.. It currently has 1 GitHub stars and 256 downloads on Packagist (latest version 0.0.1). Install it with composer require mintbridge/eloquent-sentiment. Discover more Laravel packages by mintbridge or browse all Laravel packages to compare alternatives.

Last updated

Eloquent Sentiment

Laravel 5 package for adding sentiment to eloquent models.

Installation

This package can be installed through Composer.

composer require mintbridge/eloquent-sentiment

Once installed add the service provider and facade to your app config

// config/app.php

'providers' => [
    '...',
    'Mintbridge\EloquentSentiment\SentimentServiceProvider',
];

'aliases' => [
    '...',
    'Sentiment' => 'Mintbridge\EloquentSentiment\SentimentFacade',
];

You'll also need to publish and run the migration in order to create the database table.

php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="config"
php artisan vendor:publish --provider="Mintbridge\EloquentSentiment\SentimentServiceProvider" --tag="migrations"
php artisan migrate

The configuration will be written to config/eloquent-sentiment.php. The options have sensible defaults but you should change the user model to match the one used in your application.

Usage

This package will allow your users to add sentiment to models used in your application. To do so the models that you would like to be sentimentable must use the Sentimentable trait and implement SentimentableInterface.

use Mintbridge\EloquentSentiment\Sentimentable;
use Mintbridge\EloquentSentiment\SentimentableInterface;

class Article extends Eloquent implements SentimentableInterface {

    use Sentimentable;
    ...
}

Sentiment can be added to models by using the SentimentManager or more easily with the Sentiment facade:

$article = Article::find(1);

// add article as a favourite
Sentiment::add('like', $article);

// remove article from by a favourite
Sentiment::remove('like', $article);

// toggle article as being a favourite
Sentiment::toggle('like', $article);

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

Star History Chart