每次开新发票时,我都使用laravel通知向特定用户发送电子邮件。
通过这封电子邮件,我发送了一个带有发票链接的 URL,如下所示:
public function toMail($notifiable)
{
$url = url('/invoices/'.$this->id.'/edit');
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url($url))
->line('Thank you for using our application!');
}
输出 URL = 客户/发票/6c081f60-d25a-4798-bf6e-bcc4924b1e53/编辑
我的控制器:
public function edit($id)
{
$invoice = InvoicesData::where('invoice_id', $id)->first();
return view('customer.invoices.edit', compact('invoice'));
}
如何从控制器函数中的 url 中检索"id"参数?
我应该删除我的网址还是有其他选择?
就像拉拉维尔在网络中的使用一样.php
Route::resource('customer/invoices', 'CustomerInvoiceController', ['names'
=> [
'index' => 'customer.invoices.index',
'store' => 'customer.invoices.store',
'edit' => 'customer.invoices.edit',
]]);
提前感谢!
如果这是完整的网址,那么随机ID是第三段customer/invoices/6c081f60-d25a-4798-bf6e-bcc4924b1e53/edit
。 在拉拉维尔,你可以做...
$id = $request->segment(3);
或
$id = Request::segment(3);