0

Im curently learning laravel with QR code. I use the code that I got from github. Its working fine when I run the html file. But when I add to my code in php file (Laravel) I get some error.

The error:

ErrorException (E_ERROR) Call to undefined function formatName() (View: C:\xampp\htdocs\museumadityawarman\resources\views\topups\scan_qrcode.blade.php)

The error points out to this part of my view:

<span v-if="camera.id == activeCameraId" :title="formatName(camera.name)" class="active">{{ formatName(camera.name) }}</span>

<li v-for="scan in scans" :key="scan.date" :title="scan.content"><script type="text/javascript">{{scan.content}}</li>

I've tried to change from

{{ formatName(camera.name) }}

To

<script>formatName(camera.name);</script>

This does fix the error message but I still can't get the value.

This is some of Javascript code:

 methods: {
    formatName: function (name) {
      return name || '(unknown)';
    },
    selectCamera: function (camera) {
      this.activeCameraId = camera.id;
      this.scanner.start(camera);
    }   }

Thanks, sorry for my bad english.

2
  • What is camera? Is it a php variable or javascript variable? You can't mix PHP and javascript codes, because PHP only runs before the page is sent to the browser, and javascript after. Commented Sep 7, 2018 at 13:29
  • camera is from javascript. Im not use php command there, I just add from html that i get form github to Laravel Commented Sep 7, 2018 at 13:57

1 Answer 1

1

You have to put an @ before the {{ formatName(camera.name) }}

@{{ formatName(camera.name) }}

Look at the Laravel doc https://laravel.com/docs/5.6/blade#blade-and-javascript-frameworks:

Since many JavaScript frameworks also use "curly" braces to indicate a given expression should be displayed in the browser, you may use the @ symbol to inform the Blade rendering engine an expression should remain untouched

EDIT:

Since you look like you are using vue.js, you could also use the directive v-text like so :

<span v-if="camera.id == activeCameraId" :title="formatName(camera.name)" class="active" v-text="formatName(camera.name)"></span>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bro. I will try your suggestions. And i will comment if my problem fixed :)
Glad I could help! Have a nice day :-)

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.