Laravel blade not getting secure URL inside of javascript
hi,
I am using these codes on same laravel blade file, and get different result ,
inside of the <script>....</script> it doesnt get https url.
Domain is : https://www.domain.com
FIRST CODE
{{ url('post') }}
Result : https://www.domain.com/post
SECOND CODE
<script type="text/javascript">
var postURL = "{{ url('post') }}";
</script>
Result : http://www.domain.com/post
And i dont want it to be always https , if domain is secure i want it to be https else http. Do you have any idea for this?
That doesnt seem to make any sense. The url() function does not know that you have wrapped it in script tags
The only thing that makes a difference is the url you used to load the route that created this blade view
@Snapey i can use the url() function out of script tags normally, and it shows https. But some how inside of script tags it shows only http.
I have tried to name those routes on web.php and and used route() function , and again inside of script tags it shows only http.
its about the Url you used to load the page. It gets the protocol from the request
@Snapey do you know how to fix it? on hosting domain setting ?
No I can't help based on what you have provided.
If you think it is related to <script> then put the url inside and outside the script tags on the same page. I'm sure you will see no difference.
Is your site hosted behind an SSL proxy like Cloudflare? It could be passing http requests to your code and appearing as https externally.
@Snapey I have already tested as you said :
"If you think it is related to then put the url inside and outside the script tags on the same page. I'm sure you will see no difference.",
This is the result i am having, problem is about script tags
I am unable to reproduce your problem.
View
<div>
{{ url('post') }}
</div>
<script type="text/javascript">
var postURL = "{{ url('post') }}";
</script>
Browser result
<div>
https://testbed.test/post
</div>
<script type="text/javascript">
var postURL = "https://testbed.test/post";
</script>
Can you reproduce it in a plain view like that?
@skliche I tried your example too.
and i figured out.
when i use {{ url('post') }} single, it shows http.
but when used inside of src="{{ url('post') }}" or href="{{ url('post') }}" it shows https.
really strange stuation.
and you use the same method each time you test it?
Please or to participate in this conversation.