• <small id='NYFRP'></small><noframes id='NYFRP'>

    1. <legend id='NYFRP'><style id='NYFRP'><dir id='NYFRP'><q id='NYFRP'></q></dir></style></legend>
      <i id='NYFRP'><tr id='NYFRP'><dt id='NYFRP'><q id='NYFRP'><span id='NYFRP'><b id='NYFRP'><form id='NYFRP'><ins id='NYFRP'></ins><ul id='NYFRP'></ul><sub id='NYFRP'></sub></form><legend id='NYFRP'></legend><bdo id='NYFRP'><pre id='NYFRP'><center id='NYFRP'></center></pre></bdo></b><th id='NYFRP'></th></span></q></dt></tr></i><div id='NYFRP'><tfoot id='NYFRP'></tfoot><dl id='NYFRP'><fieldset id='NYFRP'></fieldset></dl></div>

      <tfoot id='NYFRP'></tfoot>
          <bdo id='NYFRP'></bdo><ul id='NYFRP'></ul>

        如何在 laravel 中定义路由组名称

        How to define route group name in laravel(如何在 laravel 中定义路由组名称)

        <i id='RvGmM'><tr id='RvGmM'><dt id='RvGmM'><q id='RvGmM'><span id='RvGmM'><b id='RvGmM'><form id='RvGmM'><ins id='RvGmM'></ins><ul id='RvGmM'></ul><sub id='RvGmM'></sub></form><legend id='RvGmM'></legend><bdo id='RvGmM'><pre id='RvGmM'><center id='RvGmM'></center></pre></bdo></b><th id='RvGmM'></th></span></q></dt></tr></i><div id='RvGmM'><tfoot id='RvGmM'></tfoot><dl id='RvGmM'><fieldset id='RvGmM'></fieldset></dl></div>
          <legend id='RvGmM'><style id='RvGmM'><dir id='RvGmM'><q id='RvGmM'></q></dir></style></legend>

            <bdo id='RvGmM'></bdo><ul id='RvGmM'></ul>
                  <tbody id='RvGmM'></tbody>
                <tfoot id='RvGmM'></tfoot>

                <small id='RvGmM'></small><noframes id='RvGmM'>

                • 本文介绍了如何在 laravel 中定义路由组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有什么方法可以在 laravel 中定义路由组的名称吗?

                  Is there any way to define the name of route group in laravel?

                  我试图通过这个来完成的是知道当前请求属于哪个组,这样我就可以通过当前路由操作激活主菜单和子菜单:

                  What I'm trying to accomplish by this is to know that the current request belongs to which group so I can make active the main menu and sub menu by the current route action:

                  代码:

                  Route::group(['prefix'=>'accounts','as'=>'account.'], function(){
                      Route::get('/', 'AccountController@index')->name('index');
                      Route::get('connect', 'AccountController@connect')->name('connect');
                  });
                  
                  Route::group(['prefix'=>'quotes','as'=>'quote.'], function(){
                      Route::get('/', 'QuoteController@index')->name('index');
                      Route::get('connect', 'QuoteController@create')->name('create');
                  });
                  

                  导航 HTML 代码

                  <ul>
                      <li> // Add class 'active' when any route is open from account route group
                          <a href="{{route('account.index')}}">Accounts</a>
                          <ul>
                              <li> // Add class 'active' when connect sub menu is clicked
                                  <a href="{{route('account.connect')}}">Connect Account</a>
                              </li>
                          </ul>
                      </li>
                      <li> // Add class 'active' when any route is open from quote route group
                          <a href="{{route('quote.index')}}">Quotes</a>
                          <ul>
                              <li> // Add class 'active' when create sub menu is clicked
                                  <a href="{{route('quote.create')}}">Create Quote</a>
                              </li>
                          </ul>
                      </li>
                  </ul>
                  

                  现在我想要的是调用一个函数或其他东西,它会给我当前路由的组名.

                  Now what I want is to call a function or something which will give me the current route's group name.

                  例子:

                  1. 如果我在索引或创建报价页面 getCurrentRouteGroup() 应该返回 quote
                  2. 如果我在帐户的索引或连接页面上,getCurrentRouteGroup() 应该返回 account
                  1. If I'm on index or create page of quotes getCurrentRouteGroup() should return quote
                  2. If I'm on index or connect page of accounts getCurrentRouteGroup() should return account

                  推荐答案

                  这应该可行:

                  Route::group(['prefix'=>'accounts','as'=>'account.'], function(){
                      Route::get('/', ['as' => 'index', 'uses' => 'AccountController@index']);
                      Route::get('connect', ['as' => 'connect', 'uses' = > 'AccountController@connect']);
                  });
                  

                  看这里以获得解释并在 官方文档(在路由组和命名路由下).

                  Look here for an explanation and in the official documentation (under Route Groups & Named Routes).

                  更新

                  {{ $routeName = Request::route()->getName() }}
                  
                  @if(strpos($routeName, 'account.') === 0)
                      // do something
                  @endif
                  

                  Rohit Khatri 的替代品

                  function getCurrentRouteGroup() {
                      $routeName = IlluminateSupportFacadesRoute::current()->getName();
                      return explode('.',$routeName)[0];
                  }
                  

                  这篇关于如何在 laravel 中定义路由组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    • <bdo id='Nykte'></bdo><ul id='Nykte'></ul>

                        <tbody id='Nykte'></tbody>
                    • <tfoot id='Nykte'></tfoot>

                          <small id='Nykte'></small><noframes id='Nykte'>

                          <legend id='Nykte'><style id='Nykte'><dir id='Nykte'><q id='Nykte'></q></dir></style></legend>
                          <i id='Nykte'><tr id='Nykte'><dt id='Nykte'><q id='Nykte'><span id='Nykte'><b id='Nykte'><form id='Nykte'><ins id='Nykte'></ins><ul id='Nykte'></ul><sub id='Nykte'></sub></form><legend id='Nykte'></legend><bdo id='Nykte'><pre id='Nykte'><center id='Nykte'></center></pre></bdo></b><th id='Nykte'></th></span></q></dt></tr></i><div id='Nykte'><tfoot id='Nykte'></tfoot><dl id='Nykte'><fieldset id='Nykte'></fieldset></dl></div>