Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/app/Http/Controllers/Shop/ |
<?php
namespace App\Http\Controllers\Shop;
use App\Models\Product;
use App\Models\ProductReview;
use App\Notifications\StatusNotification;
use App\Models\User;
use Illuminate\Http\Request;
use Notification;
class ProductReviewController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$reviews = ProductReview::getAllReview();
return view('backend.review.index')->with('reviews', $reviews);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'rate' => 'required|numeric|min:1',
]);
$product_info = Product::getProductBySlug($request->slug);
// return $product_info;
// return $request->all();
$data = $request->all();
$data['product_id'] = $product_info->id;
$data['user_id'] = $request->user()->id;
$data['status'] = 'active';
// dd($data);
$status = ProductReview::create($data);
$user = User::where('role', 'admin')->get();
$details = [
'title' => 'New Product Rating!',
'actionURL' => route('product-detail', $product_info->slug),
'fas' => 'fa-star',
];
Notification::send($user, new StatusNotification($details));
if ($status) {
request()->session()->flash('success', 'Thank you for your feedback');
} else {
request()->session()->flash('error', 'Something went wrong! Please try again!!');
}
return redirect()->back();
}
/**
* Display the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$review = ProductReview::find($id);
// return $review;
return view('backend.review.edit')->with('review', $review);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$review = ProductReview::find($id);
if ($review) {
// $product_info=Product::getProductBySlug($request->slug);
// return $product_info;
// return $request->all();
$data = $request->all();
$status = $review->fill($data)->update();
// $user=User::where('role','admin')->get();
// return $user;
// $details=[
// 'title'=>'Update Product Rating!',
// 'actionURL'=>route('product-detail',$product_info->id),
// 'fas'=>'fa-star'
// ];
// Notification::send($user,new StatusNotification($details));
if ($status) {
request()->session()->flash('success', 'Review Successfully updated');
} else {
request()->session()->flash('error', 'Something went wrong! Please try again!!');
}
} else {
request()->session()->flash('error', 'Review not found!!');
}
return redirect()->route('review.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$review = ProductReview::find($id);
$status = $review->delete();
if ($status) {
request()->session()->flash('success', 'Successfully deleted review');
} else {
request()->session()->flash('error', 'Something went wrong! Try again');
}
return redirect()->route('review.index');
}
}