App\Http\Controllers\ProductsController::getTopRated PHP Method

getTopRated() public static method

This method is able to return the higher rate product list, everything will depends of $point parameter.
public static getTopRated ( [integer] $point = '5', [integer] $limit = 5, [boolean] $tags = false ) : [array
$point [integer]
$limit [integer]
$tags [boolean]
return [array
    public static function getTopRated($point = '5', $limit = 5, $tags = false)
    {
        if ($tags == true) {
            $products = Product::select(['id', 'tags', 'rate_count', 'rate_val'])->WhereNotNull('tags')->free()->orderBy('rate_count', 'desc')->orderBy('rate_val', 'desc')->take($limit)->get();
            $_tags = [];
            $products->each(function ($prod) use(&$_tags) {
                $array = explode(',', $prod->tags);
                foreach ($array as $value) {
                    if (trim($value) != '') {
                        $_tags[] = trim($value);
                    }
                }
            });
            return array_unique($_tags, SORT_STRING);
        } else {
            $products = Product::select(['id', 'name', 'description', 'features', 'price', 'type', 'stock'])->free()->orderBy('rate_count', 'desc')->orderBy('rate_val', 'desc')->take($limit)->get();
            return $products;
        }
    }

Usage Example

Example #1
0
 public function index()
 {
     $panel = ['center' => ['width' => 10], 'left' => ['width' => 2, 'class' => 'home-no-padding']];
     $helperProd = new productsHelper();
     $carousel = $helperProd->suggest('carousel');
     $viewed = $helperProd->suggest('viewed', 8);
     $categories = $helperProd->suggest('categories');
     $purchased = $helperProd->suggest('purchased');
     $suggestion = ['carousel' => $carousel, 'viewed' => $viewed, 'categories' => $categories, 'purchased' => $purchased];
     $helperProd->resetHaystack();
     //reseting session id validator
     $events = [];
     if (config('app.offering_free_products')) {
         $events = FreeProduct::getNextEvents(['id', 'description', 'min_participants', 'max_participants', 'participation_cost', 'start_date', 'end_date'], 4, date('Y-m-d'));
     }
     $tagsCloud = ProductsController::getTopRated(0, 20, true);
     $allWishes = '';
     $user = \Auth::user();
     if ($user) {
         $allWishes = Order::ofType('wishlist')->where('user_id', $user->id)->where('description', '<>', '')->get();
     }
     $i = 0;
     //carousel implementation
     $jumbotronClasses = ['jumbotron-box-left', 'jumbotron-box-right'];
     //carousel implementation
     $banner = ['/img/banner/01.png', '/img/banner/02.png', '/img/banner/03.png', '/img/banner/04.png'];
     // $this->createTags();
     return view('home', compact('panel', 'suggestion', 'allWishes', 'events', 'tagsCloud', 'jumbotronClasses', 'i', 'banner'));
 }
All Usage Examples Of App\Http\Controllers\ProductsController::getTopRated