0

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);
0

2 Answers 2

1

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.

0

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.