public function storeReviewForProduct($slug, $comment, $rating)
 {
     $product = Product::whereSlug($slug)->firstOrFail();
     //$this->user_id = Auth::user()->id;
     $this->comment = $comment;
     $this->rating = $rating;
     $product->reviews()->save($this);
     // recalculate ratings for the specified product
     $product->recalculateRating($rating);
 }
<?php

Route::resource('admin/seo', 'AdminSeoController');
Route::resource('admin/control-panel', 'AdminControlPanelController');
// This is the route for the Backbone pagination
Route::get('api/products', 'ApiProductsController@getIndex');
// Route for Homepage - displays all products from the shop
Route::get('/', function () {
    $products = Product::all();
    $categories = Category::all();
    return View::make('index', array('products' => $products, 'categories' => $categories));
});
// Route that shows an individual product by its slug
Route::get('products/{slug}', function ($slug) {
    $product = Product::whereSlug($slug)->firstOrFail();
    $categories = Category::all();
    $seo = $product->seo()->first();
    // Get all reviews that are not spam for the product and paginate them
    $reviews = $product->reviews()->with('user')->approved()->notSpam()->orderBy('created_at', 'desc')->paginate(100);
    return View::make('products.single', array('product' => $product, 'reviews' => $reviews, 'categories' => $categories, 'seo' => $seo));
});
// Route that handles submission of review - rating/comment
Route::post('products/{slug}', array('before' => 'csrf', function ($slug) {
    $input = array('comment' => Input::get('comment'), 'rating' => Input::get('rating'));
    // instantiate Rating model
    $review = new Review();
    // Validate that the user's input corresponds to the rules specified in the review model
    $validator = Validator::make($input, $review->getCreateRules());
    // If input passes validation - store the review in DB, otherwise return to product page with error message
    if ($validator->passes()) {
        $review->storeReviewForProduct($slug, $input['comment'], $input['rating']);
Example #3
0
 /**
  * [editProduct description]
  * @param  [type] $slug [description]
  * @return [type]       [description]
  */
 public function editProduct($slug)
 {
     $product = Product::whereSlug($_GET['product'])->with('product_infomations')->first();
     $data['content_header'] = "Edit " . $product['name'];
     $data['product'] = $product;
     $data['url'] = URL::route('product.edit.save', $slug);
     $data['submit'] = "Edit Product";
     return View::make('admin.product.new', $data);
 }