Get base URL of Laravel 5 page using jQuery

Submitted by cpaddison - 9 years ago

Get the base URL of your Laravel 5 app page available anywhere in your JavaScript for jQuery to use. To do this you could have the following code in your template.blade.php file...

<script type="text/javascript">
var APP_URL = {!! json_encode(url('/')) !!};
</script>

//Then you can access that variable anywhere in your JavaScript, like so:
console.log(APP_URL);