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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.