tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.94k stars 250 forks source link

How to get $user->id for the route #409

Closed B3K4682 closed 3 years ago

B3K4682 commented 3 years ago

Hello, I want to generate every user id in datatable I'm using: route('admin.user.details', 2 ) But at the number (2) I want to use $user->id. but it's javascript error - " > " is undefined.

How to do that?

bakerkretzmar commented 3 years ago

If you're trying to echo out the number 2 somewhere in a Blade template it would probably look something like route('admin.user.details', {{ $user->id }}), if you're in Javascript or a Vue template or something and you have a Javascript user variable, it would be route('admin.user.details', user.id).

B3K4682 commented 3 years ago

I have $user variable but it's not finding and getting error ,,users is not defined". userView = route('admin.user.details', users.id);

bakerkretzmar commented 3 years ago

I can't tell if you're in a Javascript file or a Blade template, but that error isn't coming from Ziggy—you'll need to make sure you have defined a user or $user variable. In Blade you would probably need to pass it to the view from your controller, in Javascript it will depend a lot on your setup. Can you share a longer snippet of the file you're working with?

B3K4682 commented 3 years ago

Ops nvm, I fixed it. In javascript file I had no User variable 😆