[英]how to get latest date record from array in laravel
Hello all i am using laravel elequont i want to fetch record of latest date from array can someone help how can i achieve this.大家好,我正在使用 laravel elequont 我想从数组中获取最新日期的记录有人可以帮助我如何实现这一点。 mention below is my array下面提到的是我的阵列
[
{
"id": 266,
"customer_id": 19,
"bill_no": 239,
"bill_period": "monthly",
"from_date": "2021-07-01",
"to_date": "2021-07-31",
"month": "Jul 2021",
"total_litres": "617",
"amount": "42573",
"previous_balance": "177140",
"total_amount": "219713",
"amount_paid": "0",
"pending_amount": "219713",
"adjusted": "0",
"status": 1,
"created_at": "2021-07-31 02:33:54",
"updated_at": null,
"customer_name": "amit farm"
},
{
"id": 267,
"customer_id": 20,
"bill_no": 240,
"bill_period": "monthly",
"from_date": "2021-07-01",
"to_date": "2021-07-31",
"month": "Jul 2021",
"total_litres": "1240",
"amount": "85560",
"previous_balance": "265995",
"total_amount": "351555",
"amount_paid": "0",
"pending_amount": "351555",
"adjusted": "0",
"status": 1,
"created_at": "2021-07-31 02:33:54",
"updated_at": null,
"customer_name": "rahul farm"
},
{
"id": 321,
"customer_id": 19,
"bill_no": 294,
"bill_period": "monthly",
"from_date": "2021-08-01",
"to_date": "2021-08-31",
"month": "Aug 2021",
"total_litres": "620",
"amount": "42780",
"previous_balance": "219713",
"total_amount": "262493",
"amount_paid": "0",
"pending_amount": "262493",
"adjusted": "0",
"status": 1,
"created_at": "2021-09-01 03:39:26",
"updated_at": null,
"customer_name": "amit farm"
},
{
"id": 322,
"customer_id": 20,
"bill_no": 295,
"bill_period": "monthly",
"from_date": "2021-08-01",
"to_date": "2021-08-31",
"month": "Aug 2021",
"total_litres": "1245",
"amount": "85905",
"previous_balance": "351555",
"total_amount": "437460",
"amount_paid": "0",
"pending_amount": "437460",
"adjusted": "0",
"status": 1,
"created_at": "2021-09-01 03:39:26",
"updated_at": null,
"customer_name": "rahul farm"
},
{
"id": 368,
"customer_id": 19,
"bill_no": 341,
"bill_period": "monthly",
"from_date": "2021-09-01",
"to_date": "2021-09-30",
"month": "Sep 2021",
"total_litres": "600",
"amount": "41400",
"previous_balance": "262493",
"total_amount": "303893",
"amount_paid": "0",
"pending_amount": "95378",
"adjusted": "0",
"status": 1,
"created_at": "2021-10-01 02:26:46",
"updated_at": null,
"customer_name": "amit DAIRY"
},
{
"id": 369,
"customer_id": 20,
"bill_no": 342,
"bill_period": "monthly",
"from_date": "2021-09-01",
"to_date": "2021-09-30",
"month": "Sep 2021",
"total_litres": "1200",
"amount": "82800",
"previous_balance": "437460",
"total_amount": "520260",
"amount_paid": "0",
"pending_amount": "294692",
"adjusted": "0",
"status": 1,
"created_at": "2021-10-01 02:26:46",
"updated_at": null,
"customer_name": "rahul farm"
},
]
this is my query这是我的查询
$wdata= DB::table('weekly_billing')
->Join('customers', 'weekly_billing.customer_id', '=', 'customers.id')
->select('weekly_billing.*','customers.customer_name','customers.bill_period')
->where('weekly_billing.bill_period','monthly')
->get();
I want to fetch the record of latest month like here i want to fetch sept record only i am using laravel any help would be appreciated我想获取最近一个月的记录,就像这里我只想获取 sept 记录,我正在使用 laravel 任何帮助将不胜感激
You can modify your query like so:您可以像这样修改查询:
$wdata= DB::table('weekly_billing')
->join('customers', 'weekly_billing.customer_id', '=', 'customers.id')
->select('weekly_billing.*','customers.customer_name','customers.bill_period')
->where('weekly_billing.bill_period','monthly')
->where('month', Carbon::now()->format('M Y'))
->get();
the MY
format should result in Sep 2021
(at the time of writing). MY
格式的结果应该是Sep 2021
年Sep 2021
(在撰写本文时)。
A generic approach based on your billing span would be:基于您的计费范围的通用方法是:
$wdata= DB::table('weekly_billing')
->join('customers', 'weekly_billing.customer_id', '=', 'customers.id')
->select('weekly_billing.*','customers.customer_name','customers.bill_period')
->whereRaw(Carbon::now()->format('Y m d').' BETWEEN from_date AND to_date')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.