Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
Passing php variables to javascript in laravel syntax errors

Question 1) When passing PHP variables to be used in javascript if the variables hold an array, it will result in an error relating to the attempted conversion of array to string when trying to pass these values in the following manner. Why do I have to json encode the value before it works when $var itself is already an array?

PHP Code

$var = ['test'];

Javascript

Let var = {!!$var!!};

Solution

Let var = {!!json_encode($var)!!} 

Question 2 when passing PHP variables that may have the value of null to javascript, it may result in a syntax error. For example,

PHP Code

$var = null;

Javascript

Let var = {{$var}};

Error

Var = ; (Syntax error)

Failed Solution

if({{$var}}){
    let var = {{$var}};

Solution

Let var = '{{$var');

Why does my attempted solution of only setting the value of the var when $var has a value fails?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

simply put laravel echo in doouble quote

<script>
 let var1="{{$var}}";
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda