php - Laravel continously check if there is a new item in an array -
i new laravel , want implement system in projects "alerts" users when there new comment on 1 of there posts.
i query comments on posts of logged in user , put in array , send view. goal make alert icon or when there new item in array.
is there easy way laravel helper function or something? can't seem find in laravel documentation.
is right way approach this?
here's code:
$uid = auth::user()->id; $projects = user::find($uid)->projects; //comments if (!empty($projects)) { foreach ($projects $project) { $comments_collection[] = $project->comments; } } if (!empty($comments_collection)) { $comments = array_collapse($comments_collection); foreach($comments $com) { if ($com->from_user != auth::user()->id) { $ofdate = $com->created_at; $commentdate = date("d m", strtotime($ofdate)); $comarr[] = array( 'date' => $ofdate, $commentdate,user::find($com->from_user)->name, user::find($com->from_user)->email, project::find($com->on_projects)->title, $com->on_projects, $com->body, project::find($com->on_projects)->file_name, user::find($com->from_user)->file_name ); } } } else { $comarr = ""; }
if can set me on right way reach goal thankful! :)
thanks in advance
what looking observer.
so observer watch comment model, , in observer handler check post , user id , send notification or other step need carry out.
Comments
Post a Comment