2014-04-02 120 views
-1

Laravel在重定向路由时遇到问题;我在做什么是这样的:Laravel中的重定向路由

enter image description here

正如你可以看到,我想,当选择选项更改为使href值的按钮。我想它重定向到一个显示控制器使用:

var deptHref = "{{{action('[email protected]')}}}"; 
var actionDeptHref = deptHref + '/' + id; 

但后来当我尝试运行它,它给了我在我的浏览器这个网址:

enter image description here

我不知道这里的“% 7Badmin_documents%7D“来自于,因为我期待得到”admin-documents/show/8“?

我在我的路线这样做是:

enter image description here

这就是为什么我在我的浏览器URL期待的是“管理的文档/显示/ 8”。

我也检查了我的php artisan路线,看看我有:

enter image description here

所以我有两个“admin-documents.show”这是影响了我的路线?如果这影响它,为什么:

var href = "{{{action('[email protected]')}}}"; 
    var id = $('#department-options').val(); 
    href = href + "/" + id; 

正在工作?

回答

0

使用3个大括号使得Laravel逃不出你的HTML,只使用2:

var href = "{{action('[email protected]')}}"; 
+0

我这样做了,不过它不工作.. – Aoi

0

您的路线预计{ID},其中您通常使用的助手(http://laravel.com/docs/helpers#urls)的参数,可以在供应但是,你不能提供它,因为它是动态的,所以一种方法是使用绝对URL。所以

var href = "{{{action('[email protected]')}}}"; 
var id = $('#department-options').val(); 
href = href + "/" + id; 

将成为

var href = "/admin-documents/show/" + $('#department-options').val(); 
+0

但创建工作,不知道为什么它是不是在表演。因为它适用于创建多数民众赞成在为什么我试图再做一次。你能告诉我为什么吗? TNN的答复 – Aoi

+0

坚持下去,我一直没有读得不够好,创建不需要ID,显示路线。我会编辑我的答案以避免混淆。 – nvisser