使用laravel的javascript变量

I'm trying to use my javascript variable with laravel.But I'm getting this error.

error:

Use of undefined constant tag - assumed 'tag'

Use of undefined constant tag - assumed 'tag'

and this is my code.

var tag = location.tagCode;
var rfidString = ('{!!\App\Rfid::where('rfid_id', tag)->first()!!}')
var rfid = JSON.parse(rfidString);

You have to do XHR request to server along with tag then retrieve RFID from server and then assign it to javascript variable.

The way you are doing not possible.

Try something like this, use json_encode with Array of data.

<script>
    window.variable = {!! json_encode([
        'variable' => 'value',
    ]) !!};
</script>