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

179
Vistas
Console.log does not show result based on variable value

I'm using Laravel 5.8 and in this project, I wanted to show some results in Javascript based on the variable which is sent to View.

So at the Controller, I have added this:

$title = "";
if($popup->showtitle == 1){
    $title = $popup->title;
}

return view("frontend.home")->with('title',$title);

Then at the view:

<script>
   var title = JSON.parse("{{ json_encode($title) }}");
   if(!title){
        console.log(1);
   }else{
        console.log(2);
   }
</script>

So basically, if title does not have any value, it should be showing 1 at the Console bar, otherwise 2 must be appears.

But the problem is, it does not show anything at all!

So what's going wrong out there? How can I properly get the result based on this variable value?

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

0

in controller

    $title = "your title";
    return view('rontend.home')->with([
        'title' => $title,
    ]);

in blade

<script>
    $(document).ready(function() {
    var title = {!! json_encode($title) !!};
    console.log(title);
    });
</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