【发布时间】:2018-10-27 11:08:05
【问题描述】:
我正在尝试创建一个发票编号,例如 - HCL/LF/02/2018,其中新发票的编号将加一。有人能帮我得到预期的invoice_no吗?我在我的控制器中尝试过这样的事情 -
public function create()
{
$check = OrderProformaInvoice::orderBy('created_at', 'DESC')->get();
$number = 01;
$year = date('Y');
if (count($check) > 0) {
$invoiceNo = OrderProformaInvoice::latest()->first(['invoice_no']);
$arr = array('HCL','LF', $invoiceNo + 1, $year);
$newInvoiceNo = implode("/",$arr);
}else{
$arr = array('HCL','LF', $number, $year);
$newInvoiceNo = implode("/",$arr);
}
return view('admin.marchendaising.order-proforma-invoices.create', compact('newInvoiceNo'));
}
在我看来,表单输入字段是-
<input type="text" name="invoice_no" class="form-control" value="{{ $newInvoiceNo }}">
【问题讨论】:
-
运行这段代码会得到什么?还有发票号码,因为您已经拨打了数据库电话以获取所有发票,您的
$invoiceNo可能只是count($check) + 1。在年份下,您可以写$numOfInvoices = count(check),然后拨打$numOfInvoices++。编辑:我刚刚注意到您甚至没有在创建功能中保存新发票,因此除非您保存它们,否则数字永远不会增加? -
你能转储
$invoiceNo吗?是对象还是整数? -
对于我之前的条目,我手动插入
invoice_no字段HCL/LF/01/2018
标签: php mysql laravel explode implode