I have simple javascript code:
var photo = data.photo;
console.log("{{url('" + photo + "')}}");
Here I use laravel url() method. But I can't display value photo inside laravel method. How I can display it?
It's a bad practice to mix Blade syntax with JS. You should do something like this in one of Blade templates:
<script>
let window.url = {{ url('/') }}
</script>
Then in JS files use this variable:
var photo = data.photo;
console.log(window.url + photo);
You'll find another related code example in my Laravel best practices repo.
Laravel best practices book.var siteurl = "{{url('/')}}"; code?{{ url('/') }} in javascript code will be not work.
console.log(photo){{url(stuff)}}intohttp://someurl, but this code does not run on the server, it's all client-side.http://domain.loc/uploads/photo.jpgurl()javascript var, yes @James ?