Php 在控制器中是否有检索随机url参数的方法
每次我开新发票时,我都会使用laravel notifiable向特定用户发送电子邮件 通过这封电子邮件,我发送了一个带有发票链接的url,如下所示:Php 在控制器中是否有检索随机url参数的方法,php,laravel,laravel-5.8,Php,Laravel,Laravel 5.8,每次我开新发票时,我都会使用laravel notifiable向特定用户发送电子邮件 通过这封电子邮件,我发送了一个带有发票链接的url,如下所示: public function toMail($notifiable) { $url = url('/invoices/'.$this->id.'/edit'); return (new MailMessage) ->line('The introduction to the notification.')
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”参数
我应该删除我的url还是有其他选择
就像laravel在web.php中使用的一样
Route::resource('customer/invoices', 'CustomerInvoiceController', ['names'
=> [
'index' => 'customer.invoices.index',
'store' => 'customer.invoices.store',
'edit' => 'customer.invoices.edit',
]]);
提前谢谢 如果这是完整url,则随机id是第三段
客户/发票/6c081f60-d25a-4798-bf6e-bcc4924b1e53/edit
。在拉威尔你可以做
$id = $request->segment(3);
或
什么你已经取回了没有?这只是您要使用的
$id
变量?是的,我只希望id变量的参数值在路由更改时不可靠,但它工作正常,谢谢!那个随机的字符串总是保持相同的长度吗?(即36个字符)您可以使用$request->segments()
获取数组中的所有段,然后使用strlen()
在数组中搜索长度为36的字符串以获取您的id。
$id = Request::segment(3);