melogail / laravel-reviews
Simple reviews system with rating for laravel framework
dev-master
2020-05-22 06:04 UTC
This package is auto-updated.
Last update: 2024-04-22 15:00:49 UTC
README
laravel-Reviews
Laravel Tags package for Laravel framework applications, it is useful for adding tags to different models in the application, useful for Blogs, eCommerce...etc
How to use
Installation
- Install the package using
composer
in your project.
composer require melogail/laravel-reviews
- Publish the package migration files, config file
config/laravel-reviews
, and migration files.
php artisan vendor:publish --tag=reviews_data
- Update your autoload files
composer dump-autoload -o
- Migrate your new migration files
php artisan migrate
- Add the
reviewable
trait inside your desired models to have tags
use Melogail\LaravelTags\Reviweable; class Articles extends Model { use Reviewable; // model code follow... }
- Inside
config/
directory, add the model class wherereviewer_id
will match. ex:users
table.
'models' => [ 'reviewer' => [ 'class' => App\User::class, // model reviewer ] ]
Usage
To get all the tags added for specific model, use a foreach
loop:
foreach ($article->reviews as $review) { $tag->name; }
To add review, you use the addReview($data = [])
method on your object.
$article->addReview($data)