Giter Site home page Giter Site logo

laravel-reviewable's Introduction

laravel-reviewable

Software License Travis StyleCI Total Downloads

This package adds a reviewable feature to your app.

Install

Laravel Version 5.7+

composer require naoray/laravel-reviewable

Laravel Version 5.6+

composer require naoray/laravel-reviewable:1.1.*

Laravel Version 5.5

composer require naoray/laravel-reviewable:1.0.*

publish config: php artisan vendor:publish --provider="Naoray\LaravelReviewable\LaravelReviewableServiceProvider"

Usage

First, add the Naoray\LaravelReviewable\Traits\HasReviews trait to your model you want to add reviews to.

use Naoray\LaravelReviewable\Traits\HasReviews;

class Post extends Model
{
    use HasReviews;

    // ...
}

Now you can create a review by:

// from reviewable entity
Post::first()->createReview(5, 'Example review text', $author);

// author is assumed to be logged in and executing this operation
Post::first()->createReview(10);

// with helper
review($post, 5, 'Example Text', $author);

and receive review scores by:

// summarizes all scores
Post::first()->score;

// gives the average of all scores
Post::first()->avg_score;

Using your own Review-Model

If you just want to change the global configuration to use your own Review-Model, just create a new Model and reference it in the reviewable.models.review config.

If you do not want to change the global review Model you can take a look at this issue for an example configuration.

Testing

Run the tests with:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

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

laravel-reviewable's People

Contributors

dependabot[bot] avatar naoray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-reviewable's Issues

[How to] Use a different custom Review model for each reviewable

While playing around with the package, I found myself where I needed to use reviews for two different models. However, I also wanted to use a custom Review model for each of these reviewables.

The current implementation, through the config file only allows me to override the Review model globally. I figured out a way to do this individually for each reviewable and thought I'd share how I did it so others might be able to do the same.

On the reviewable model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Naoray\LaravelReviewable\Traits\HasReviews;

class TravelTip extends Model
{
    use HasReviews;

    /**
     * Override HasReviews trait method to use appropriate model.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function reviews()
    {
        return $this->morphMany(
            'App\TravelTipReview', // Replace this with your custom Review model
            'reviewable'
        );
    }

On your custom Review model:

<?php

namespace App;

use Naoray\LaravelReviewable\Models\Review;

class TravelTipReview extends Review
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'reviews'; // Required for Laravel to avoid trying to resolve the table name from the model name

    // Add your custom properties and methods here

All that's left to do is call your custom Review model is controllers if needed!

Incorrect syntax for vendor:publish in readme

Hey there,

Great package! However it seems there may be a small error in the readme, spend about 15 minutes scratching my head about this one!

The readme should read php artisan vendor:publish --provider="Naoray\LaravelReviewable\LaravelReviewableServiceProvider". The double quotes were missing around the Service Provider's path, preventing the command from functioning correctly.

Additionally, you may want to specify the command is also required to publish the migration.

Thanks for the great package!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.