在脚本标签(Laravel)中使用Auth函数

时间:2018-07-21 11:05:49

标签: javascript laravel

伙计们,我正在尝试在Auth文件中的script标签中使用blade函数,但是当我检查其来源时似乎收到了黄色警告在谷歌。是否可以在脚本标记中使用Auth函数,或者有其他替代方法吗?有人能帮忙吗?提前致谢。

这是我在脚本标签中的代码片段

<script type="text/javascript">
    $('button').click(function(){
        //CONST DATA
        const prefix = "QATS";
        const url = "http://qr5.dev.ificonsultancy.net/api/sendData";

        //Extract Data
        var lecturer_id = Auth::user()->id;     //HERE IS THE ERROR
        var faculty_code = $( "#Faculty" ).val();
        var programme_code = $( "#Programme" ).val();
        var class_code = $("#Class").val();

        //Location Coordinates
        var gps_school_lng =  "101.5597904";
        var gps_school_lat =  "3.0923526";

        //URL Concatenation
        var urlContent = prefix.concat("|",url,"|",lecturer_id,"|",faculty_code,"|",programme_code,"|",class_code,"|",gps_school_lat,"|",gps_school_lng);

        //Add src to #qrImg
        $("img#qrImg").attr('src',"https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl="+urlContent+"&choe=UTF-8");
        console.log("pass");
    });
</script>

1 个答案:

答案 0 :(得分:1)

是的,只需使用小胡子语法:

var lecturer_id = '{{ Auth::user()->id; }}'