File: /home/imensosw/public_html/amanda/app/ChatHistory.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class chatHistory extends Model
{
protected $table="chat_history";
// use SoftDeletes;
protected $fillable = [
'from','to','message','fileName','read_status'
];
public static function getUnredMessageCount($from,$to)
{
$result= ChatHistory::where(array("from"=>$from,"to"=>$to,"read_status"=>"unread"))->count();
return $result;
}
/*public static function getLatestTimeStamp($from,$to)
{*/
// $parameter['from']=$from;
// $parameter['to']=$to;
/*$result = ChatHistory::
where(array("from"=>$from, "to"=>$to, "read_status"=>"unread"))->orwhere(array("from"=>$to, "to"=>$from, "read_status"=>"unread" ))->orderBy('created_at','desc')->first();*/
//$result = ChatHistory::where('created_at', ChatHistory::max('created_at'))->orderBy('created_at','desc')->first();
/* print_r($result['created_at'];);
die();*/
/* where(function($query) use ($parameter)
{
$query->where('chat_history.from', '=', $parameter['from'])
->where('chat_history.to', '=', $parameter['to']);
})
->orwhere(function($query) use ($parameter)
{
$query->where('chat_history.from', '=', $parameter['to'])
->where('chat_history.to', '=', $parameter['from']);
}) */
/*->orderBy('id','desc')->first();*/
/*return $result['created_at'];
}*/
public static function updateUnredMessage($from,$to)
{
$result= ChatHistory::
where(array("from"=>$from,"to"=>$to,"read_status"=>"unread"))
->update(array("read_status"=>"read"));
return $result;
}
}