使用 Request::is() 函数和命名路由 Laravel

using Request::is() function with named Routes Laravel

我正在做 Request::is('/') 这给了我 true example.com 现在我正在使用命名路由和名称 welcome

Route::get('/', function () {
    return view('admin_panel.welcome');
})->name('welcome');

Request::is(route('welcome')) returns false

我该怎么办。注意:我将其用于导航中的活动状态

我使用 Request::url() == route('welcome') 实现了这个,这给了我 true for example.com

您可以使用routeIs方法:

Request::routeIs('welcome');