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

268
Views
¿Cómo paso una variable del archivo js al controlador laravel para hacer una consulta basada en la variable tomada de un elemento en el que se hizo clic?

este es el código en el controlador laravel

 $data = table::where('field',$var)->get();

este es el archivo js del que estoy tratando de recibir la variable para pasarla a la consulta

 function clicked(var) { console.log(var); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El front-end deberá enviar datos al back-end a través de una solicitud HTTP. Esto se puede hacer a través de AJAX. Hay buenas bibliotecas que puede usar para hacer esto, como AXIOS si está usando Laravel con Vue.JS. Aquí hay un ejemplo de cómo usarlo:

 axios.post('/URL_HERE', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
about 4 years ago · Juan Pablo Isaza Report

0

Este es el método alternativo que he elegido para ir con. este es el archivo js:

 var region = "regionInput"; $.ajaxSetup({ headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')}, }); $.ajax({ method: "POST", url: "/test-route", //dataType:"jsonp", // dataType:"String", data:{regionName: region}, success: function(result){ console.log(result); } });

este es el archivo web.php

 Route::post('/test-route',[App\Http\Controllers\regionsController::class, 'testMethod']);

esta es la función en el controlador

 public function testMethod(Request $request){ return response()->json($request->input("regionName"));
about 4 years ago · Juan Pablo Isaza 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!