2014-04-02 123 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