How to place vue variable inside a laravel bracket

余生颓废 提交于 2019-12-04 08:17:16

You're mixing up server side and client side code there. You're passing @{{course.id}} as a parameter to a PHP function, so you'll probably be getting a syntax error.

You should use Laravel to output your route and then in your HTML/Blade you can output a Vue variable using the @{{ }} syntax.

<a href="{{ route('courses.show') }}?course_id=@{{ course.id }}">@{{ course.title }}</a>

That will generate a URL like http://yourdomain.com/courses/path/ and stick ?course_id= on the end of it.

My guess is that you're trying to use a route with a parameter in it, rather than a query string. In which case, you should try something like this (Not tested):

<a href="{{ route('courses.show', '') }}/@{{ course.id }}">@{{ course.title }}</a>

Note that I have put quotes ' around the second parameter to route and I have omitted the @ since we're hoping to directly output {{ course.id }} and we're in PHP, not Blade.

With any luck your URL will be generated as something like this:

http://yourdomain.com/courses/path/{{ course.id }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!