Created
April 18, 2023 05:53
-
-
Save djamol/80e60f691c9bcd495f9f06dd9ca022ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\mongo; | |
use Carbon\Carbon; | |
use MongoDB\BSON\UTCDateTime; | |
use DB; | |
use Jenssegers\Mongodb\Eloquent\Model; | |
class BotHistory extends Model | |
{ | |
protected $connection = 'mongodb'; | |
protected $collection = 'bot_history'; | |
// set the fillable properties | |
protected $fillable = [ | |
'bot_id', | |
'input', | |
'output', | |
'intent', | |
'customer_id', | |
'website_id', | |
'ip' | |
]; | |
protected $dates = ['created_at', 'updated_at']; | |
/* | |
public function getLog() { | |
return $this->belongsTo(Log::class); | |
} | |
*/ | |
public static function rawQuery($query,$REQmatch=null,$start=null,$end=null) | |
{ | |
if($start!=null && $end!=null){ | |
$date = Carbon::parse($start); | |
$utcDate = new UTCDateTime($date->timestamp * 1000); | |
$date2 = Carbon::parse($end); | |
$utcDate2 = new UTCDateTime($date2->timestamp * 1000); | |
$match =['created_at' => [ | |
'$gte' => $utcDate, | |
'$lte' => $utcDate2 | |
]]; | |
if($REQmatch!=null){ | |
$match=array_merge($match,$REQmatch); | |
} | |
$query2 = [ | |
[ | |
'$match' => $match | |
], | |
]; | |
$nw = array_merge($query,$query2); | |
}else{ | |
$nw =$query; | |
} | |
$history = self::raw(function($collection) use($nw) { | |
return $collection->aggregate($nw); | |
}); | |
return $history; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GET/POST API REQUEST INPUT DATA