如何在Laravel中的URL中写多个参数的路由? [英] how to write route for multiple parameters in url in laravel?

查看:896
本文介绍了如何在Laravel中的URL中写多个参数的路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在url中传递两个参数.我的网址是 http://localhost/buyforfund/fundraising/public/campaign_details/64

I want to pass two parameters in url. My url is http://localhost/buyforfund/fundraising/public/campaign_details/64

我想要这个网址:
http://localhost/buyforfund/fundraising/public/campaign_details/64/campaign_product_details/26
在按钮上单击,我要这个URL,然后从路径名称中提供按钮链接.但是会发生错误.

I want this url :
http://localhost/buyforfund/fundraising/public/campaign_details/64/campaign_product_details/26
on button click I want this url and I give the button link from route name. But an error occurs.

按钮链接:

<a href="{{ route('campaign_product_details.detail',$result->id) }}" class="hvr-float-shadow">View</a>

错误:

缺少[Route:campaign_product_details.detail] [URI:campaign_details/{campaign_id}/campaign_product_details/{product_id}]必需的参数.

Missing required parameters for [Route: campaign_product_details.detail] [URI: campaign_details/{campaign_id}/campaign_product_details/{product_id}].

我的路线:

Route::get('campaign_details/{campaign_id}/campaign_product_details',function(){
        return view('/front/campaign_product_details');
    });
Route::get('campaign_details/{campaign_id}/campaign_product_details/{product_id}','front\CampaignDetailsController@showCampaignProductDetails')->name('campaign_product_details.detail');

推荐答案

尝试传递如下两个参数:

Try to pass two parameters like below:

Route::get('campaign_details/{campaign_id}/campaign_product_details/{product_id}', [
'as' => 'showCampaignProductDetails', 'uses' => 'CampaignDetailsController@showCampaignProductDetails']);

您认为:

route('showCampaignProductDetails',['campaingn_id'=>$campaign_id,'product_id'=>$productId]);

这篇关于如何在Laravel中的URL中写多个参数的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆