duancaishun4812 2019-05-20 09:37
浏览 177
已采纳

从Route获取值

I'm in developing a dynamic view composer and I need to get the values of routes.

for example, I have these three routes:

Route::group(['prefix' => 'join', 'as' => 'join-'], function () {
    Route::get('/', 'JoinController@index')->name('index');

    Route::group(['prefix' => '{j}/signin', 'as' => 'signin-'], function () {
       Route::get('/', 'SigninController@index')->name('index');

       Route::group(['prefix' => '{f}/forget', 'as' => 'forget-'], function () {
           Route::get('/', 'ForgetController@index')->name('index');
       });

    });
});

now I want to catch the $j and $f values in my view composer.

I can get the name of my routes via Route::currentRouteName() but I need to get the values that passed to this routes.

because I need to use route() to create a link, for join- there is no any problem because we don't need to pass any parameter but in join-signin- and join-signin-forget- I have Laravel error.

  • 写回答

1条回答 默认 最新

  • dongmeng2687 2019-05-20 11:05
    关注

    I found the solution, I will write it down might others have this question too.

    to get the current route parameters we can use the below method:

    Route::current()->parameters();
    

    or

    Route::getCurrentRequest()->route()->parameters;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器