基于文档:
确定请求路径是否匹配模式
if (Request::is('admin/*'))
// What are the support patterns in laravel 4 request beside the wildcard?
{
//
}
我似乎找不到比通配符提供更多示例的文档。
伙计们,我真的想切换活动菜单css
在这种情况下:
{{ (Request::is('home')) ? 'active' : '' }}
或
{{ (Request::segment(1) == 'home') ? 'active' : '' }}
或
{{ (Request::path() == 'home/special') ? 'active' : '' }}
或者自己制作
{{ (preg_match('whatever you want here', Request::path()) ? 'active' : '') }}
编辑:查看Laravel核心中的Request::is()函数:
/**
* Determine if the current request URI matches a pattern.
*
* @param string $pattern
* @return bool
*/
public function is($pattern)
{
foreach (func_get_args() as $pattern)
{
if (str_is($pattern, $this->path()))
{
return true;
}
}
return false;
}
因此,您实际上可以传入任何"模式",它将与str_is()进行匹配
<a href="#" {{ (Request::is('url*')) ? 'class=active' : '' }}>Link</ a>
试试这个:
Request::is('url*')
Request::is('url/*')
示例:
<a href="#" {{ (Request::is('products*')) ? 'class=active' : '' }}>Link</ a>
或
<a href="#" {{ (Request::is('products')) ? 'class=active' : '' }}>Link</ a>
<a href="#" {{ (Request::is('products/*')) ? 'class=active' : '' }}>Link< /a>