Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
use script JavaScript in contoller laravel

i need to use this script inside a laravel controller. the script uses a facial recognition library to compare the faces that are in the photos. How can I use this code inside a public function?

    const imageUpload = document.getElementById('imageUpload')
Promise.all([
    faceapi.nets.faceRecognitionNet.loadFromUri('/models'),
    faceapi.nets.faceLandmark68Net.loadFromUri('/models'),
    faceapi.nets.ssdMobilenetv1.loadFromUri('/models'),
    faceapi.nets.tinyFaceDetector.loadFromUri('/models')
  ]).then(start)

 
  
  

async function start() {
  
  document.body.append('Loaded')
  imageUpload.addEventListener('change', async () => {
    
    image = await faceapi.bufferToImage(imageUpload.files[0])
    
    const descriptions = []
    const detections1 = await faceapi.detectAllFaces(image).withFaceLandmarks().withFaceDescriptors();
    
    const faceMatcher = new faceapi.FaceMatcher(detections1, 0.6)

    var a = 0;
    const images = [];
    for (var i = 100; i <= 618; i++) {
      let image = 0;
      let img = new Image();
      img.src = 'test/' + i + '.jpeg';
      image = i + '.jpeg';
  
      const results = await faceapi.detectAllFaces(img).withFaceLandmarks().withFaceDescriptors()
      results.forEach(fd => {
        const bestMatch = faceMatcher.findBestMatch(fd.descriptor)

        if (bestMatch.label == "person 1") {
          
          images[a] = image;
          a++;
        }
        
      })
    
     
      }
  })
  

  
  }

This project is to work as an API, I don't want it to have views, the user will just have an APP in react native making requests to the laravel API

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Laravel is php. The php interpreter does not execute javascript. You can run JS in a browser OR in a nodeJS micro-service. If you really want to get funky you can setup a headless browser on your server.

about 4 years ago · Santiago Gelvez Report

0

You can't run javascript in Laravel controller. Also this function loads from the DOM, so it needs a document.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!