Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将laravel..env变量包含到js文件中_Php_Laravel_Environment Variables - Fatal编程技术网

Php 如何将laravel..env变量包含到js文件中

Php 如何将laravel..env变量包含到js文件中,php,laravel,environment-variables,Php,Laravel,Environment Variables,我正在尝试将laravel.env变量包含到我的js文件中我的文件名是custom-script.js,我的js代码是: function sendBusinessDetails(postForm) { $.ajax({//Process the form using $.ajax() type: 'post', //Method type url: 'http://localhost:8000/Process', //Your form pr

我正在尝试将laravel.env变量包含到我的js文件中我的文件名是custom-script.js,我的js代码是:

     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',
和我的.env文件包含

 APP_URL=http://localhost:8000
如何将APP_URL=替换为我的URL:“”

非常感谢你的帮助

            $.ajax({
            type: 'post', //Method type
            url: '{{env("API_URL")}}/api/apikey?api_key

在您的
blade
文件中:

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

这是另一种选择

从公用目录中删除自定义脚本.js文件

在您的路线中(web.php)

脚本控制器中

class ScriptController extends Controller
{

    public function index(){
        return response()->view('custom-script')->header('Content-Type','application/javascript');
    }

}
现在将js代码放入定制脚本.blade.php文件中

alert('{{ env("APP_URL") }}');

url:'{{env(“APP_url”)}}/'+'Process'
这对你不起作用吗?这里不起作用。请看我的问题,我已经分享了
url:{{env(“API_url”)}+'/process'+'/API/apikey?API_key'
你需要连接进程忘记旧的url。请看我的eidt问题实际上,你想做什么?$.ajax({type:'post',//方法类型url:'connectApi+'&我想用API_url替换标记=
class ScriptController extends Controller
{

    public function index(){
        return response()->view('custom-script')->header('Content-Type','application/javascript');
    }

}
alert('{{ env("APP_URL") }}');