Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url Laravel 4-路由未重置为根_Url_Laravel_Routes - Fatal编程技术网

Url Laravel 4-路由未重置为根

Url Laravel 4-路由未重置为根,url,laravel,routes,Url,Laravel,Routes,我遇到了一个问题,当我使用href访问路线时,例如 example.com/user/foo 然后单击带有href的链接,如 example.com/cart/bar URL设置为 example.com/user/cart/bar 我得到一个错误。问题是URL没有重置为根目录,而是将子目录(“用户”)保留在URL中 以下是指向用户路由的链接示例: <li><a href="/user/{{ Auth::user()->username }}">{{ Auth::u

我遇到了一个问题,当我使用href访问路线时,例如

example.com/user/foo

然后单击带有href的链接,如

example.com/cart/bar

URL设置为

example.com/user/cart/bar

我得到一个错误。问题是URL没有重置为根目录,而是将子目录(“用户”)保留在URL中

以下是指向用户路由的链接示例:

<li><a href="/user/{{ Auth::user()->username }}">{{ Auth::user()->firstName }} {{ Auth::user()->lastName }}</a></li>
对视图的结果调用:

return View::make('profile.user')
            ->with('user', $user);
return View::make('store.cart')->with('products', Cart::contents());
此时,URL为:

example.com/user/john_smith

但是,假设我想查看我的购物车,它的href为:

<li><a href="store/cart">Cart</a></li>
对视图的结果调用:

return View::make('profile.user')
            ->with('user', $user);
return View::make('store.cart')->with('products', Cart::contents());
URL应为:

example.com/store/cart

但事实是

example.com/user/store/cart

我得到一个“NotFoundHttpException”

您可以使用
url()
helper函数来生成一个绝对url,例如:

<li><a href="{{ url('store/cart') }}">Cart</a></li>