我有以下表格和以下代码来检索商店订单;
我的目的是根据创建的时间获取订单并订购它们,并按照升序顺序订购delivery_from时间字段,同时属于created_at orderby。
有效查询的示例将获取以下内容;
delivery_from: 10:00, created_at: 10/10/2018
delivery_from: 12:00, created_at: 10/10/2018
delivery_from: 09:00, created_at: 15/10/2018
delivery_from: 15:00, created_at: 15/10/2018
我目前的代码就是这样取而代之的;
delivery_from: 09:00, created_at: 15/10/2018
delivery_from: 10:00, created_at: 10/10/2018
delivery_from: 12:00, created_at: 10/10/2018
delivery_from: 15:00, created_at: 15/10/2018
$store = auth('manager')->user->store;
$orders = $store->orders()->orderBy('created_at', 'desc')->orderBy('delivery_from', 'asc')->get();
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('store_id');
$table->unsignedInteger('delivery_method');
$table->float('final_price', 8, 2);
$table->float('delivery_price', 8, 2);
$table->unsignedInteger('payment_type');
$table->unsignedInteger('status');
$table->boolean('paid')->default(false);
$table->time('delivery_from');
$table->time('delivery_to');
$table->timestamps();
});
答案 0 :(得分:2)
我认为您应该首先按delivery_from
订购,如下所示:
$orders = $store->orders()->orderBy('delivery_from', 'asc')->orderBy('created_at', 'desc')->get();