Пример #1
0
 public function hasThree()
 {
     $collection_product = CollectionProduct::where('collection_id', '=', $this->id)->get();
     if ($collection_product->count() > 2) {
         return true;
     } else {
         return false;
     }
 }
 public function searchBySlug($slug)
 {
     $coll = Collection::where('slug', '=', $slug)->first();
     $id = $coll->id;
     //  $products = Product::add_created_by_and_category($products);
     //  $coll = Collection::find($id);
     $collection = CollectionProduct::where('collection_id', '=', $id)->get();
     //  dd($collection) ;
     $collection_list = [];
     $creator = $coll->created_by;
     $creator = User::find($creator);
     foreach ($collection as $pro) {
         $product_id = $pro->product_id;
         $product = Product::find($product_id);
         $product = Product::add_created_by_and_category($product);
         if ($product != null) {
             $created_by = $product['created_by'];
             $category = Category::find($product['category_id']);
             $category = $category['category'];
             $user = User::find($created_by);
             array_add($collection, 'category', $category);
             array_add($collection, 'created_by_name', $user['name']);
             array_push($collection_list, $product);
         }
     }
     $collection = collect($collection_list)->sortByDesc('votes');
     return ['collection-info' => $coll, 'creator' => $creator, 'products' => $collection->values()->all()];
 }
Пример #3
0
 public function viewUnapprovedProduct($id)
 {
     $user = Auth::user();
     if ($user != null && $user->hasRole('admin')) {
         $coll = Collection::find($id);
         $collection = CollectionProduct::where('collection_id', '=', $id)->get();
         //  dd($collection) ;
         $collection_list = [];
         $creator = $coll->created_by;
         $creator = User::find($creator);
         foreach ($collection as $pro) {
             $product_id = $pro->product_id;
             $product = Product::find($product_id);
             $product = Product::add_created_by_and_category($product);
             if ($product != null) {
                 $created_by = $product['created_by'];
                 $category = Category::find($product['category_id']);
                 $category = $category['category'];
                 $user = User::find($created_by);
                 array_add($collection, 'category', $category);
                 array_add($collection, 'created_by_name', $user['name']);
                 array_push($collection_list, $product);
             }
         }
         return view('admin.viewUnapprovedCollection')->with('products', $collection_list)->with('collection', $coll);
     } else {
         return view('admin.login');
     }
 }