Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hasen39's avatar

javascript ,php and laravel

i work with both javascript and php but setTimeout only works one what is the problem

here is the code

setTimeout(function(){

@php

    $database_time=App\time::find(1);
    $hour=$database_time->hour;
    $minute=$database_time->minute;
    $from=date('h:i:s');
    // echo $from;
    if(!(Session::exists('start_time'))){
    Session::put('start_time',strtotime($from));
    }

    $endtime=date('h:i:s',strtotime('+'.$hour.' hours'.' '.$minute.' '.'minutes',Session::get('start_time')));
    $endtime;
    $from=strtotime($from);
    $endtime=strtotime($endtime);
    $differencetime=($endtime-$from);
    $display_date = date('h:i:s',$differencetime);

@endphp var value="" document.getElementById('demo').innerHTML=value;

},500);

and on the above i have

this code
0 likes
3 replies
Cronix's avatar

You're mixing 2 different languages. That doesn't work. A javascript setTimeout() won't execute php code. Javascript runs/lives in the browser. PHP runs/lives on the server.

Please or to participate in this conversation.