Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include laravel ..env variable into js file

i am trying to include laravel .env variable into my js file my file name is custom-script.js and my js code is:

     function sendBusinessDetails(postForm) {

    $.ajax({//Process the form using $.ajax()
        type: 'post', //Method type
        url: 'http://localhost:8000/Process', //Your form processing file URL
        data: postForm, //Forms name
        dataType: 'json',

and my .env file contain

 APP_URL=http://localhost:8000

how i can replace APP_URL=http://localhost:8000 into my url: 'http://localhost:8000/Process',

Your help will be highly appreciated

            $.ajax({
            type: 'post', //Method type
            url: '{{env("API_URL")}}/api/apikey?api_key
like image 917
shahzad1122 Avatar asked Nov 25 '25 10:11

shahzad1122


1 Answers

In your blade file:

<script>
    var action = "{{ env("APP_URL") }}"
</script>

In your js:

url : action+'/process',
like image 64
Sand Of Vega Avatar answered Nov 26 '25 23:11

Sand Of Vega



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!