每次使用新发票时,我都会使用可通知的laravel向特定用户发送电子邮件。
通过这封电子邮件,我将发送一个带有发票链接的网址,如下所示:
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!');
}
输出网址=客户/发票/ 6c081f60-d25a-4798-bf6e-bcc4924b1e53 / edit
我的控制器:
public function edit($id)
{
$invoice = InvoicesData::where('invoice_id', $id)->first();
return view('customer.invoices.edit', compact('invoice'));
}
如何从控制器函数的网址中检索“ id”参数?
我应该去除网址还是有其他选择?
像laravel在web.php中使用的
Route::resource('customer/invoices', 'CustomerInvoiceController', ['names'
=> [
'index' => 'customer.invoices.index',
'store' => 'customer.invoices.store',
'edit' => 'customer.invoices.edit',
]]);
谢谢!
答案 0 :(得分:1)
如果这是完整网址,则随机ID为第三段customer/invoices/6c081f60-d25a-4798-bf6e-bcc4924b1e53/edit
。在Laravel中,您可以...
$id = $request->segment(3);
或
$id = Request::segment(3);