Download core/app/Http/Controllers/Admin/ReviewController.php from pnacorp/codeplus: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/pnacorp/codeplus/resolve/main/core/app/Http/Controllers/Admin/ReviewController.php
- Command line
-
hf download hf://pnacorp/codeplus/core/app/Http/Controllers/Admin/ReviewController.php
-
curl -L -o ReviewController.php https://huggingface.co/pnacorp/codeplus/resolve/main/core/app/Http/Controllers/Admin/ReviewController.php
1.5 kB
| namespace App\Http\Controllers\Admin; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Rating; | |
| use App\Models\Review; | |
| use App\Models\User; | |
| class ReviewController extends Controller | |
| { | |
| public function index($authorId = 0) | |
| { | |
| $pageTitle = 'Reviews'; | |
| $reviews = Review::latest()->with(['product']); | |
| if ($authorId) $reviews->where('author_id', $authorId); | |
| $reviews = $reviews->paginate(getPaginate()); | |
| return view('admin.review.index', compact('pageTitle', 'reviews')); | |
| } | |
| public function destroy($id) | |
| { | |
| $review = Review::findOrFail($id); | |
| $product = $review->product; | |
| $review->delete(); | |
| $user = User::findOrFail($product->user_id); | |
| $user->total_review = $user->reviews()->count(); | |
| $user->avg_rating = $user->reviews()->avg('rating'); | |
| $user->save(); | |
| $product->total_review = $product->reviews()->count(); | |
| $product->avg_rating = $product->reviews()->avg('rating'); | |
| $product->save(); | |
| $rating = Rating::where('value', '>=', @$product->avg_rating ?? 0)->first() ?? Rating::orderBy('value', 'desc')->first(); | |
| if($rating){ | |
| $rating->product_count -= 1; | |
| if ($rating->product_count == 0) $rating->product_count = 0; | |
| $rating->save(); | |
| } | |
| $notify[] = ['success', 'Review deleted successfully']; | |
| return back()->withNotify($notify); | |
| } | |
| } | |