当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::add_created_by_and_category方法代码示例

本文整理汇总了PHP中app\Product::add_created_by_and_category方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::add_created_by_and_category方法的具体用法?PHP Product::add_created_by_and_category怎么用?PHP Product::add_created_by_and_category使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Product的用法示例。


在下文中一共展示了Product::add_created_by_and_category方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: viewUnapprovedProduct

 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');
     }
 }
开发者ID:ShehabSunny,项目名称:ProductZap,代码行数:29,代码来源:AdminController.php

示例2: searchBySlug

 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()];
 }
开发者ID:ShehabSunny,项目名称:ProductZap,代码行数:28,代码来源:CollectionController.php

示例3: getByDate

 public function getByDate(Request $request)
 {
     $date = $request->input('date');
     $query = $request->input('query');
     if ($query == 'today') {
         $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '=', $date)->get();
     } else {
         if ($query == 'yesterday') {
             $yesterday = explode('-', $request->input('date'));
             $yesterday[2] = $yesterday[2] - 1;
             $yesterday = implode($yesterday, '-');
             $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '=', $yesterday)->get();
         } else {
             if ($query == 'this_month') {
                 $month = explode('-', $request->input('date'));
                 $month[2] = '0';
                 $month = implode($month, '-');
                 $start_date = explode('-', $request->input('date'));
                 if ($start_date[2] < 3) {
                     $start_date[2] = 0;
                     $start_date = implode($start_date, '-');
                 } else {
                     $start_date[2] = $start_date[2] - 2;
                     $start_date = implode($start_date, '-');
                 }
                 $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>=', $month)->having('created_at_date', '<=', $start_date)->get();
                 // $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>', $month)->get();
             } else {
                 if ($query == 'last_month') {
                     $start_date = explode('-', $request->input('date'));
                     $start_date[1] = $start_date[1] - 1;
                     if ($start_date[1] == 0) {
                         $start_date[0] = $start_date[0] - 1;
                         $start_date[1] = 12;
                     }
                     $start_date[2] = 0;
                     $end_date = $start_date;
                     $start_date = implode($start_date, '-');
                     // return ;
                     $end_date[2] = 31;
                     $end_date = implode($end_date, '-');
                     //      return $end_date;
                     $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>=', $start_date)->having('created_at_date', '<=', $end_date)->get();
                 } else {
                     if ($query == 'this_year') {
                         $year = explode('-', $request->input('date'));
                         $year[1] = '0';
                         $year[2] = '0';
                         $year = implode($year, '-');
                         // return $year;
                         $start_date = explode('-', $request->input('date'));
                         if ($start_date[1] < 3) {
                             $start_date[1] = 0;
                             $start_date[2] = 0;
                             $start_date = implode($start_date, '-');
                             //   return $start_date;
                         } else {
                             $start_date[2] = 31;
                             $start_date[1] = $start_date[1] - 2;
                             $start_date = implode($start_date, '-');
                             //   return $start_date;
                         }
                         $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>=', $year)->having('created_at_date', '<=', $start_date)->get();
                         //   $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>', $year)->get();
                     } else {
                         if ($query == 'last_year') {
                             $start_year = explode('-', $request->input('date'));
                             $start_year[0] = $start_year[0] - 1;
                             $start_year[1] = '0';
                             $start_year[2] = '0';
                             $end_year = $start_year;
                             $start_year = implode($start_year, '-');
                             $end_year[0] = $end_year[0];
                             $end_year[1] = '12';
                             $end_year[2] = '31';
                             $end_year = implode($end_year, '-');
                             // return $year;
                             $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>=', $start_year)->having('created_at_date', '<=', $end_year)->get();
                         } else {
                             if ($query == 'between') {
                                 $start_day = $request->input('start_day');
                                 $end_day = $request->input('end_day');
                                 $products = Product::orderBy('created_at_date', 'DESC')->orderBy('votes', 'DESC')->having('created_at_date', '>=', $start_day)->having('created_at_date', '<=', $end_day)->get();
                             }
                         }
                     }
                 }
             }
         }
     }
     // $products;
     //  return $products->sortByDesc('created_at');
     $products = Product::add_created_by_and_category($products);
     return response()->json(['products' => $products]);
     //  return json('products.index', ['products'=>$products]);
 }
开发者ID:ShehabSunny,项目名称:ProductZap,代码行数:96,代码来源:ProductController.php


注:本文中的app\Product::add_created_by_and_category方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。