Skip to content

Commit

Permalink
Rate and Review Module v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RamzyVirani committed Jan 10, 2020
0 parents commit efbadca
Show file tree
Hide file tree
Showing 27 changed files with 1,656 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
74 changes: 74 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Rate And Review Module for the [Boilerplate](https://github.com/RamzyVirani/laravel-boilerplate)

Install this package with my boilerplate to add Rate and Review feature in your application. This module registers below components in the application.

This module implements Laravel's polymorphic relations so that you can easily attach one or more models.


PS: This module is highly dependant on the [Boilerplate](https://github.com/RamzyVirani/laravel-boilerplate). Because this module extends some of the base classes Boilerplate has.


**General**

- Configuration
- Helper
- Migration
- Model
- Repository

**Admin**

- Controller
- Data Table
- Request Classes
- Routes
- Views

**API**
- Controllers
- Criteria
- Request Classes
- Routes

## How to install
Please make sure that you have completely installed the boilerplate including and most importantly executed the migration from the boilerplate.

Execute below command to add this package in your project's composer dependencies.
```
composer require ramzyvirani/rateandreview "*"
```

Execute below command to publish views and config
```
php artisan vendor:publish --tag=RamzyVirani\RateAndReview\RateAndReviewServiceProvider
```

Execute migrations to create Reviews Table, Module, Menu, Permissions

```
php artisan migrate
```

PS: You will need to login with Super Admin to grant permissions to the admin and other roles.


**How to Add Reviewable Options**

Follow below points to add reviewable options in Admin Panel's Create/Edit forms and also use human readable instance type in Index Details Views.

- Create a new Review Model in your application.
- Extend it from `RamzyVirani\RateAndReview\Models\Review`.
- Declare a public static property (array) named `$INSTANCE_TYPE` (E.g. in the original model).
- Use FQDN of the polymorphic relations as the key and Human readable text as value
- Change the fqdn in `config/rateandreview.php`

## How to Extend Features

To Modify/Extend any functionality, Create a new class and extend it from the original Then, change the namespaces and fqdn in the `config/rateandreview.php`. Implement only those methods you want to modify.

- RamzyVirani\RateAndReview\Criteria\ReviewCriteria
- RamzyVirani\RateAndReview\DataTables\ReviewDataTable
- RamzyVirani\RateAndReview\Models\Review
- RamzyVirani\RateAndReview\Controllers\Admin\ReviewController
- RamzyVirani\RateAndReview\Controllers\Api\ReviewAPIController
- RamzyVirani\RateAndReview\Repositories\ReviewRepository
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "ramzyvirani/rateandreview",
"description": "Rate and Review Module for ramzyvirani/laravel-boilerplate",
"type": "library",
"authors": [
{
"name": "Ramzy Virani",
"email": "ramzy.rhv@gmail.com"
}
],
"require": {
"laravelcollective/html": "^5.5"
},
"extra": {
"laravel": {
"providers": [
"RamzyVirani\\RateAndReview\\RateAndReviewServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"RamzyVirani\\RateAndReview\\": "src/"
}
},
"minimum-stability": "dev"
}
196 changes: 196 additions & 0 deletions src/Controllers/Admin/ReviewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php

namespace RamzyVirani\RateAndReview\Controllers\Admin;

use App\Helper\BreadcrumbsRegister;
use App\Http\Controllers\AppBaseController;
use App\Repositories\Admin\UserRepository;
use Laracasts\Flash\Flash;
use Illuminate\Http\Response;
use RamzyVirani\RateAndReview\Requests\Admin\CreateReviewRequest;
use RamzyVirani\RateAndReview\Requests\Admin\UpdateReviewRequest;

class ReviewController extends AppBaseController
{
/** ModelName */
private $ModelName;

/** BreadCrumbName */
private $BreadCrumbName;

private $reviewRepository;

/** @var UserRepository */
private $userRepository;

public function __construct(UserRepository $userRepo)
{
$this->reviewRepository = app()->make(config('rateandreview.fqdn.Repository'));
$this->userRepository = $userRepo;
$this->ModelName = 'reviews';
$this->BreadCrumbName = 'Reviews';
}

/**
* Display a listing of the Review.
*
* @return Response
*/
public function index()
{
$reviewDataTable = app()->make(config('rateandreview.fqdn.DataTable'));

BreadcrumbsRegister::Register($this->ModelName, $this->BreadCrumbName);
return $reviewDataTable->render('rateandreview::index', ['title' => $this->BreadCrumbName]);
}

/**
* Show the form for creating a new Review.
*
* @return Response
*/
public function create()
{
BreadcrumbsRegister::Register($this->ModelName, $this->BreadCrumbName);

$users = $this->userRepository->resetCriteria()->all();

$range = range(0, 10);
array_walk($range, function (&$value, $key) {
$value .= " Star(s)";
});

$types = config('rateandreview.fqdn.Model')::$INSTANCE_TYPES;

return view('rateandreview::create')->with([
'title' => $this->BreadCrumbName,
'range' => $range,
'types' => $types,
'users' => $users->pluck('details.full_name', 'id'),
]);
}

/**
* Store a newly created Review in storage.
*
* @param CreateReviewRequest $request
*
* @return Response
*/
public function store(CreateReviewRequest $request)
{
$review = $this->reviewRepository->saveRecord($request);
Flash::success($this->BreadCrumbName . ' saved successfully.');

$redirect_to = redirect(route('admin.reviews.show', $review->id));

return $redirect_to->with([
'title' => $this->BreadCrumbName
]);
}

/**
* Display the specified Review.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$review = $this->reviewRepository->findWithoutFail($id);

if (empty($review)) {
Flash::error($this->BreadCrumbName . ' not found');
return redirect(route('admin.reviews.index'));
}

BreadcrumbsRegister::Register($this->ModelName, $this->BreadCrumbName, $review);
return view('rateandreview::show')->with(['review' => $review, 'title' => $this->BreadCrumbName]);
}

/**
* Show the form for editing the specified Review.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$review = $this->reviewRepository->findWithoutFail($id);

if (empty($review)) {
Flash::error($this->BreadCrumbName . ' not found');
return redirect(route('admin.reviews.index'));
}

$users = $this->userRepository->resetCriteria()->all();

$range = range(0, 10);
array_walk($range, function (&$value, $key) {
$value .= " Star(s)";
});

$types = config('rateandreview.fqdn.Model')::$INSTANCE_TYPES;

BreadcrumbsRegister::Register($this->ModelName, $this->BreadCrumbName, $review);
return view('rateandreview::edit')->with([
'review' => $review,
'users' => $users->pluck('details.full_name', 'id'),
'range' => $range,
'types' => $types,
'title' => $this->BreadCrumbName
]);
}

/**
* Update the specified Review in storage.
*
* @param int $id
* @param UpdateReviewRequest $request
*
* @return Response
*/
public function update($id, UpdateReviewRequest $request)
{
$review = $this->reviewRepository->findWithoutFail($id);

if (empty($review)) {
Flash::error($this->BreadCrumbName . ' not found');
return redirect(route('admin.reviews.index'));
}

$review = $this->reviewRepository->updateRecord($request, $review);

Flash::success($this->BreadCrumbName . ' updated successfully.');
if (isset($request->continue)) {
$redirect_to = redirect(route('admin.reviews.create'));
} else {
$redirect_to = redirect(route('admin.reviews.index'));
}
return $redirect_to->with(['title' => $this->BreadCrumbName]);
}

/**
* Remove the specified Review from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
$review = $this->reviewRepository->findWithoutFail($id);

if (empty($review)) {
Flash::error($this->BreadCrumbName . ' not found');
return redirect(route('admin.reviews.index'));
}

$this->reviewRepository->deleteRecord($id);

Flash::success($this->BreadCrumbName . ' deleted successfully.');
return redirect(route('admin.reviews.index'))->with(['title' => $this->BreadCrumbName]);
}
}
Loading

0 comments on commit efbadca

Please sign in to comment.