本文整理匯總了PHP中app\models\Product::orderBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::orderBy方法的具體用法?PHP Product::orderBy怎麽用?PHP Product::orderBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Product
的用法示例。
在下文中一共展示了Product::orderBy方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: products
/**
* @return \Illuminate\Http\JsonResponse
*/
public function products()
{
$distributors = Distributor::all();
$products = Product::orderBy('name')->get();
$product_count = 0;
foreach ($products as $product) {
$dist_name = Distributor::where('id', '=', $product->distributor_id);
if ($dist_name->count()) {
$dist_name = $dist_name->first()->name;
$products[$product_count]->distributor_name = $dist_name;
}
$product_count++;
}
return response()->json(['distributors' => $distributors, 'products' => $products]);
}
示例2: paginateProduct
public function paginateProduct($page)
{
return Product::orderBy('id', 'desc')->paginate($page);
}
示例3: index
/**
* Untuk menampilkan semua data product
*
* @return [type] [description]
*/
public function index()
{
return ['status' => 'success', 'products' => Product::orderBy('id', 'desc')->get()];
}
示例4: index
/**
* Show the home page to the user.
*
* @return Response
*/
public function index()
{
$data['brands'] = Brands::all();
$data['latest'] = Product::orderBy('product_id', 'desc')->take('6')->get();
return view('frontend/livesearch', $data);
}
示例5: newProducts
public function newProducts()
{
$products = Product::orderBy('created_at', 'desc')->limit(10);
return view('site.pages.popular')->with('products', $products);
}