本文整理汇总了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'));
}
示例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, 'Раздача товаров');
}
示例3: index
public function index()
{
$sanpham = Product::orderByRaw("RAND()")->take(8)->get();
return view('index', compact('sanpham'));
}
示例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 ? '✓' : '-';
}), 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;
});