@php
$allMsgs = DB::table('tm_msg')->select('tm_msg.*', 'users.name')
->LEFTJOIN('users', 'tm_msg.from_id', '=', 'users.id')
->where('tm_msg.pid', '=', $pid)->where('tm_msg.display','=','Y')
->orderBy('ent_dt', 'asc')->get();
$dt = "";
foreach($allMsgs as $msg){
$strname = "";
if (date("Y-m-d", strtotime($msg->ent_dt)) == date("Y-m-d")) {
$tme = "Today";
} else {
$tme = date('F d, Y', strtotime($msg->ent_dt));
}
if (date("Y-m-d", strtotime($msg->ent_dt)) == date('Y-m-d',
strtotime("-1
days"))) {
$tme = "Yesterday";
}
if($dt != date("d-m-Y",strtotime($msg->ent_dt))){
@endphp
{{ $tme }}
@php
$dt = date("d-m-Y",strtotime($msg->ent_dt));
}
$old = DB::table('tm_msg')->select('*')->where('id',$msg->old_id)->where('display','Y')->get();
if(count($old) > 0){
$old_msg = $old[0]->msg;
}
if($msg->from_id != Auth::user()->id){
if($msg->to_id != 0){
$to_id = $msg->to_id;
$to_id = explode('@', $to_id);
if(!in_array(Auth::user()->id, $to_id)){
continue;
}else{
for($i=0; $i < count($to_id); $i++){
if(Auth::user()->id != $to_id[$i]){
$res = DB::table("users")->where('id',$to_id[$i])->select('name')->get();
if (!empty($res[0])) {
$fname = ucwords(strtolower(strtok($res[0]->name, " ")));
$strname = $fname.", ".$strname;
}
}
}
}
}
$strname = rtrim($strname, ", ");
@endphp
@php
}else{
$strname = "";
if($msg->to_id != '0'){
$to_id = $msg->to_id;
$to_id = explode('@', $to_id);
$strname = "";
for($i=0; $i < count($to_id); $i++){
$res = DB::table("users")->where('id',$to_id[$i])->select('name')->get();
if (!empty($res[0])) {
$fname = ucwords(strtolower(strtok($res[0]->name, " ")));
$strname = $fname.", ".$strname;
}
}
}
$strname = rtrim($strname, ", ");
@endphp
@php
}
}
@endphp