takshak / adash-reviews
Reviews System for laravel
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:Blade
Requires
README
An extension to takshaktiwari/adash form reviews system. This can be attached to any any model of your application and it's fully customizable.
Implementation
Install the package with composer with given command and run the migrations php artisan migrate
composer require takshak/adash-review
Publish config file, views and components for further customization
php artisan vendor:publish --provider=Takshak\Areviews\AreviewsServiceProvider
Add component to admin sidebar, inside ul
element for getting the links in admin sidebar
<x-areviews-areviews:admin-sidebar-links />
Run migration
php artisan migrate
Use Takshak\Areviews\Traits\Models\ReviewModelTrait
to those model in which you want to implement the reviews system. This will help you to get the rating and reviews of the model. If the model is $product, rating of the model will be accessed by $product->rating
and reviews by $product->reviews
.
Now all setup is done, you can use other components according to your requirements.
Components
Admin sidebar menu
<x-areviews-areviews:admin-sidebar-links />: Use this component to show the menu item in admin sidebar
Listing reviews
<x-areviews-areviews:reviews ..... />: This component will be useful to show the list of reviews. You can list your own reviews or default latest reviews with or without pagination. Default display style will be masonry using bootstrap rows and columns. You can further customize this component after publishing the assets. This will also include the reviews form and stats. There are some arguments with this component which may help you in achieving your desired format:
-
reviews: Pass the collection of reviews which you have already digged out from the database. Only these reviews will be shown in the list.
-
model: Pass the model instance for which you want to get the reviews. Note: Please check if you have already used
ReviewModelTrait
trait to the model. You will only see the reviews of the model when firstreviews
argument is not passed or is empty. -
limit: This argument will limit the reviews which we got from
reviews
ormodel
argument. This will also act as count of per page in case ofpagination
. Default limit value is 10. -
column: Use the column classes to control the number of columns in listing. Default value is
col-lg-4 col-md-6
. It will show 3 columns on large screen, 2 in medium screen and single column in small or mobile devices. You can pass your own column classes to control the columns. You can also define it globally in config file. -
paginate: Put the value
true
orfalse
to get pagination feature on listing. This will only work if you are getting the reviews frommodel
argument not fromreviews
argument. -
addReview: Add the review btn and review form, default is true
-
reviewStats: Show reviews status or not
-
avgRating: / $countReviews: Pass the average of rating and and total reviews count to show in the heading or other places. If not password, it will run database queries to get the avr rating and total reviews count if you have passed the modal: argument, otherwise it will return 0.
Example:
Getting the latest 6 reviews from all models.
<x-areviews-areviews:reviews limit="6" />
Getting all reviews of a product with pagination.
<x-areviews-areviews:reviews :model="$product" limit="20" :paginate="true" />
Getting reviews form
<x-areviews-areviews:review-form ..... />: This component can used to store or edit the reviews. There are some arguments by which you can change the functionalities. Some fields can be removed just by changing fields array in config.
-
model: Pass the model for which you want to associate the review.
-
review: An existing review wil be passed to populate the fields. This can be used in case you are editing the review.
-
url: Put the url on which you want to submit the form. By default form will be submitted to the default url. Only pass the value if you want to change the submission url.
-
method: Default method is
POST
, if you want to change the form method you can passPUT
if you are editing the review. -
redirect: Form will be redirected back to the form after submission. If you want to goto some other page after form submission, you can pass the destination url here.
-
header: If you want to show the form header of not, pass the text to change header text or leave it blank to remove it
-
avgRating: / $countReviews: Pass the average of rating and and total reviews count to show in the heading or other places. If not password, it will run database queries to get the avr rating and total reviews count if you have passed the modal: argument, otherwise it will return 0.
Example
// for storing the review.
<x-areviews-areviews:review-form :model="$product" />
// for editing the review with other arguments
<x-areviews-areviews:review-form
method="PUT"
:model="$review->reviewable"
:review="$review"
:url="route('admin.reviews.update', [$review])"
:redirect="route('admin.reviews.index')" />
Show a single review
<x-areviews-areviews:review-card ..... />: This will display a review item, an argument named review
will be passed with the review model which will be shown.
eg. <x-areviews-areviews:review-card :review="$review" />
<x-areviews-areviews:reviews-stats ..... />: This will give you the stats of reviews and rating.
Filter / Sorting Reviews by URL
You can order the listing of reviews by passing the query parameter reviews_order
. Valid values for this parameter will be: latest, oldest, rating_asc, rating_desc
You can get only specific rating by passing query parameter reviews_rating
which will hold the value 1, 2, ..5