简体   繁体   中英

Redirecting route in Laravel

I have a problem with Laravel on redirecting route; 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. 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:

在此处输入图片说明

I wonder where the "%7Badmin_documents%7D" is coming from, because I was expecting to get "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".

I also checked my php artisan routes to see what I have:

在此处输入图片说明

So I have two " admin-documents.show " is this affecting my routes? 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. So

var href = "{{{action('AdminDocumentsController@show')}}}";
var id = $('#department-options').val();
href = href + "/" + id;

would become

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM