Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue while trying to append route parameter in js

Below is my js code that is appending the route and its parameter in anchor tag.

var href = "{!! route('ShowUserMainForm', ['RoleID'=>" + row.RoleID + "]) !!}";

var UserColumn = "<td><a href=' " + href + "'><button>Users</button></a></td>";

It gives below url

http://localhost:1234/public/system-users/%20+%20row.RoleID%20+%20

I am expecting below.

http://localhost:1234/public/system-users/1

Am I missing anything?

like image 834
Pankaj Avatar asked Jun 30 '17 05:06

Pankaj


1 Answers

No. of ways to do it:

Because {!! !!} block codes render before JavaScript code so you need to create route and then concat RoleID outside {!! !!} .

if row.RoleID is json :

var href = "public/system-users/" + row.RoleID

or

var href = "{!! route('ShowUserMainForm') !!}" + row.RoleID;

or

var href = "{!! route('ShowUserMainForm', ['RoleID'=>'']) !!}" + row.RoleID;
like image 150
Govind Samrow Avatar answered Sep 28 '22 04:09

Govind Samrow