我遇到这个问题,我需要获取这种 url localhost:8000/purchaseOrder/3/purchase/1
如果我手动输入它,它可以工作,但是当我让 laravel 自动创建 url 时,它出错并以 localhost:8000/purchaseOrder/$data-%3Eid/payable/$p-%3Eid
结束
这是我的路线
Route::get('/purchaseOrder/{id}/payable/{he}', 'AjaxController@purchaseOrder');
这是我的 Controller (到目前为止我想要的只是响应我提供的 url)
function purchaseOrder($id,$he)
{
echo $id." | ".$he;
}
这是我的观点
<a href="{{ url('purchaseOrder/$data->id/payable/$p->id') }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a><br>
最佳答案
更改 View 代码:
<a href="{{ url('purchaseOrder/'.$data->id.'/payable/'.$p->id.') }}"><button type="button" class="btn btn-success btn-sm my-1" name="button">Create Purchase Order</button></a><br>
另一种方式是这样的:
设置路由名称
Route::get('/purchaseOrder/{id}/payable/{he}', 'AjaxController@purchaseOrder')->name('purchaseOrder');
在 View 中:
<a href="{{ route('purchaseOrder',[$data->id,$p->id]) }}">
关于具有多个参数的 Laravel 5.7 自定义 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903049/