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


PHP Product::orderByRaw方法代码示例

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


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

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $sliders = Slider::all();
     $categories = Category::all();
     $products = Product::orderBy('id', 'desc')->take(12)->get();
     $discount_products = Product::where('discount', '=', 'true')->take(12)->get();
     $random_products = Product::orderByRaw("RAND()")->take(10)->get();
     return view('home', compact('sliders', 'categories', 'products', 'discount_products', 'random_products'));
 }
开发者ID:MostafaEllethy,项目名称:alexsport,代码行数:14,代码来源:HomeController.php

示例2: getSendProducts

 public function getSendProducts()
 {
     $users = User::all();
     $count_users = count($users);
     $count_success = 0;
     $max_products_per_user = config('main.max_products_per_user', 3);
     foreach ($users as $key => $user) {
         $active_products = $user->list_active_products;
         $count_active_products = count($active_products);
         if ($count_active_products >= 0 && $count_active_products < $max_products_per_user) {
             $random_product = Product::orderByRaw("RAND()")->first();
             try {
                 $user_product = UserProduct::create(['user_id' => $user->id, 'product_id' => $random_product->id]);
                 $count_success++;
             } catch (QueryException $e) {
                 //Nothing
             }
         }
     }
     $result_str = "Раздача товаров...<br>Всего юзеров: " . $count_users . ". Успешно раздали: " . $count_success;
     return Admin::view($result_str, 'Раздача товаров');
 }
开发者ID:Eduard90,项目名称:Laravel-5-Example,代码行数:22,代码来源:AdminController.php

示例3: index

 public function index()
 {
     $sanpham = Product::orderByRaw("RAND()")->take(8)->get();
     return view('index', compact('sanpham'));
 }
开发者ID:viethoanganh79,项目名称:ec2015-ute,代码行数:5,代码来源:TrangController.php

示例4: config

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
use App\Product;
use App\UserProduct;
Admin::model('App\\User')->title('Пользователи')->display(function () {
    $display = AdminDisplay::datatables();
    $display->columns([Column::checkbox(), Column::string('id')->label('ID'), Column::string('name')->label('Имя'), Column::custom()->label('Актив.')->callback(function ($instance) {
        return $instance->is_active ? '&check;' : '-';
    }), Column::string('email')->label('Email'), Column::count('products')->label('Товаров')->orderable(true), Column::count('list_active_products')->label('Акт. товаров')->orderable(true), Column::string('balance')->label('Баланс')]);
    $display->columnFilters([null, ColumnFilter::select()->model('App\\User')->display('name'), null, null, null, null]);
    $display->actions([Column::action('export')->value('Раздать товары')->icon('fa-share')->callback(function ($collection) {
        $max_products_per_user = config('main.max_products_per_user', 3);
        foreach ($collection as $key => $user) {
            $active_products = $user->list_active_products;
            $count_active_products = count($active_products);
            if ($count_active_products >= 0 && $count_active_products < $max_products_per_user) {
                $random_product = Product::orderByRaw("RAND()")->first();
                try {
                    $user_product = UserProduct::create(['user_id' => $user->id, 'product_id' => $random_product->id]);
                } catch (QueryException $e) {
                    //Nothing
                }
            }
        }
    })]);
    return $display;
})->createAndEdit(function () {
    $form = AdminForm::form();
    $form->items([FormItem::text('name', 'Name')->required(), FormItem::text('email', 'Email')->required()->unique(), FormItem::password('password', 'Пароль'), FormItem::checkbox('is_active', 'Активность')]);
    return $form;
});
开发者ID:Eduard90,项目名称:Laravel-5-Example,代码行数:31,代码来源:User.php


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