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

170
Views
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 answers
Answer question

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 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!