[英]Redirecting route in Laravel
I have a problem with Laravel on redirecting route;我在重定向路由时遇到了 Laravel 的问题; what I was doing is this:
我在做什么是这样的:
As you can see I am trying to make a href
value for a button when the select option is changed.正如您可以看到的,我正在尝试在“选择”选项更改时为按钮进行
href
值。 I wanted to redirect it to a show controller using:我想使用以下命令将其重定向到显示控制器:
var deptHref = "{{{action('AdminDocumentsController@show')}}}";
var actionDeptHref = deptHref + '/' + id;
but then when I try to run it it gives me this URL on my browser:但是当我尝试运行它时,它在我的浏览器上给了我这个 URL:
I wonder where the "%7Badmin_documents%7D" is coming from, because I was expecting to get "admin-documents/show/8"?我想知道“%7Badmin_documents%7D”是从哪里来的,因为我期待得到“admin-documents/show/8”?
What I did in my route is this:我在我的路线中所做的是:
That's why I was expecting in my browser URL is "admin-documents/show/8".这就是为什么我在我的浏览器 URL 中期望的是“admin-documents/show/8”。
I also checked my php artisan
routes to see what I have:我还检查了我的
php artisan
路线,看看我有什么:
So I have two " admin-documents.show " is this affecting my routes?所以我有两个“ admin-documents.show ”这会影响我的路线吗? If this is affecting it why does the:
如果这会影响它,为什么会:
var href = "{{{action('AdminDocumentsController@create')}}}";
var id = $('#department-options').val();
href = href + "/" + id;
is working?正在工作?
使用 3 个花括号可以让 Laravel 转义你的 HTML,只使用 2 个:
var href = "{{action('AdminDocumentsController@create')}}";
Your route expects {id}, which you'd normally supply with the params using the helper ( http://laravel.com/docs/helpers#urls ), in your case however, you can't supply it because it's dynamic, so one way to do it is to use absolute urls.您的路线需要 {id},您通常会使用 helper ( http://laravel.com/docs/helpers#urls ) 为其提供参数,但是在您的情况下,您无法提供它,因为它是动态的,所以一种方法是使用绝对网址。 So
所以
var href = "{{{action('AdminDocumentsController@show')}}}";
var id = $('#department-options').val();
href = href + "/" + id;
would become会成为
var href = "/admin-documents/show/" + $('#department-options').val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.