Download the PHP package larastash/reviews without Composer
On this page you can find all versions of the php package larastash/reviews. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download larastash/reviews
More information about larastash/reviews
Files in larastash/reviews
Package reviews
Short Description Eloquent model reviews for Laravel.
License MIT
Homepage https://github.com/larastash/reviews
Informations about the package reviews
💬⭐ Laravel Reviews
The Larastash Reviews package is a powerful Laravel package that enables you to add review functionalities to your Eloquent models.
With this package, you can easily manage reviews for various reviewable entities and perform various review-related operations.
Requirements
- Laravel ^10;
- PHP ^8.1;
Installation
To install the Larastash Reviews package, you can use Composer:
After installing the package, publish migration and config files:
Note You can edit migration and set
foreignUuid
if your user model uses a UUID.
Prepare Models
To use the Larastash Reviews package, you need to apply the Reviewable
trait to the Eloquent model that you want to make reviewable.
Additionally, you can apply the Reviewer
trait to the User model.
Usage
The following examples demonstrate the usage of the Laravel package for managing reviews.
review($product)
: Creates a newLarastash\Reviews\Review
instance for the given$product
. It returns aLarastash\Reviews\Review
instance.$product->review()
: An alternative way to create a newLarastash\Reviews\Review
instance for the given$product
. It also returns aLarastash\Reviews\Review
instance.
Creates or updates a review for the $product
entity with the provided values. The parameters $value
, $body
, $title
, $extra
, and $userId
are used to set the properties of the review.
Publish Reviews
To create a new review (uses updateOrCreate
under the hood), use the publish
method.
With Extra Data
You can pass additional data to the review, such as approved, anonymous review, recommended, etc.
Note You can also work with this data, for example, choose an average extra value or get only approved reviews.
Another User (Reviewer)
Publish review as another user.
Note By default, the overview is owned by the current authorized user (by
Auth::id()
).
Update Review
Sometimes, when we have some extra data, for example, we need to change only approved
, then we can use the update
method.
It will change the value approved
to true
, and will not affect other extra data, such as recommended
.
Of course, you can use the publish
method to update the review. But then you will need to pass the full current extra data, not just the approved = true
.
User Has Review
Check if the user has a review or not.
Delete Review
Deletes the user's review.
Total Number of Reviews
Get the total number of reviews for a entry.
Avg Value and Extras
Get the average value of a review.
Get the average extra value of a review.
Reviewable Query Builder
Get the review query builder instance.
Eager Loading
Related Reviewable Methods
Get User Reviews
This will be available if you add the Larastash\Reviews\Concerns\Reviewer
trait to the User
model.
Helpers
review()
This function, review
, is a helper function provided by the Laravel package.
It creates a new Larastash\Reviews\Review
instance for the given reviewable entity (a model that uses the Reviewable
trait). This function is particularly useful when you want to interact with the review-related methods of the Review
class for a specific model instance. It saves you from manually creating a new Review
instance each time you want to perform actions related to reviews for a specific entity.
Testing
Contributing
If you find any issues or have suggestions for improvement, please feel free to contribute by creating a pull request or submitting an issue.
Credits
- chipslays
- All Contributors
License
The MIT License (MIT). Please see License File for more information.