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?
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.