如何从 laravel 中的任何页面请求具有前缀的特定路由作为基本路由

how to request a certain route having prefix as base route from any page in laravel

假设我在一个有 URL localhost/group/123 的页面上,当我从该页面请求路由 "profile" 时,URL 看起来像这样 localhost/group/profile .但我不想要这个,我想要 URL 像这样 localhost/profile。当我请求 "profile" 路线时,它必须看起来像 localhost/profile.

当我从基本路线请求配置文件路线时,URL 就是我想要制作的,因为我从我网站上的任何地方请求这条路线。这是我在路线中制作的路线。我已经尝试过前缀,但它对我不起作用

Route::get('profile',[
           'as'=>'tech',
           function(){ echo 'tech'; }
       ] );

我在其他表格上搜索了如何解决它,但我找不到 solution.I 我很困惑如何解决它。

您应该 name 您的路线并通过 route() 调用它,如下所示:

在你的web.php中:

Route::get('profile', ['as' => 'tech', function () {
    echo 'tech';
}]);

在您的 .blade.php 视图中:

<a href="{{ route('tech') }}">Profile</a>

可在此处找到有关路由的更多信息:https://laravel.com/docs/5.2/routing