| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/app.machinox.in/app/Models/ |
Upload File : |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class NotifiedUser extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'notification_id',
'user_id',
'has_send',
'is_read',
'created_by',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = ['deleted_at', 'updated_at'];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['user'];
public function getUserAttribute()
{
if ($this->user_id) {
$info = User::where("id", $this->user_id)
->select("id", "uuid", "name", "email", "mobile_number")
->first();
if ($info) {
return $info;
}
}
if ($this->admin_user_id) {
$info = AdminUser::where("id", $this->admin_user_id)
->select("id", "uuid", "name", "email", "mobile_number")
->first();
if ($info) {
return $info;
}
}
return null;
}
public function notification()
{
return $this->hasOne(Notification::class, 'id', 'notification_id')
->select("id", "title", "description", "action", "action_id");
}
public function added_by()
{
return $this->hasOne(AdminUser::class, 'id', 'created_by')->select("id", "uuid", "name", "email", "mobile_number");
}
public const PerPageRecord = 10;
public static function GetUnReadCount()
{
return self::query()->where('user_id', USER_ID())->where('is_read', '0')->count();
}
public static function GetCount()
{
return self::query()->where('user_id', USER_ID())->count();
}
public static function GetInfo($notificationId)
{
return self::query()->with([
'added_by', 'notification'
])->where('id', $notificationId)->first();
}
public static function GetList($request,$userId = null)
{
$offset = getValue($request->input('offset'), 0);
$sort_by = getValue($request->input('sort_by'), 'notified_users.created_at');
$sort_order = getValue($request->input('sort_order'), 'DESC');
$query = self::query()->join("notifications", "notifications.id", "notified_users.notification_id")
->where("notified_users.user_id", $userId)->orderBy($sort_by, $sort_order);
$data['count'] = count($query->get());
if (isset($offset)) {
$query->offset($offset * self::PerPageRecord);
$query->limit(self::PerPageRecord);
}
$data['list'] = $query->with([
'added_by', 'notification'
])->select("notified_users.*")->orderBy($sort_by, $sort_order)->get();
$data['next_offset'] = ((count($data['list']) == self::PerPageRecord) ? (isset($offset) ? ((int) $offset + 1) : 0) : -1);
return $data;
}
public static function GetHistory($request, $id){
$offset = getValue($request->input('offset'), 0);
$sort_by = getValue($request->input('sort_by'), 'notified_users.created_at');
$sort_order = getValue($request->input('sort_order'), 'DESC');
$query = self::query()->where("notified_users.notification_id", $id)
->join("notifications", "notifications.id", "notified_users.notification_id")
->orderBy($sort_by, $sort_order);
$data['count'] = count($query->get());
if (isset($offset)) {
$query->offset($offset * self::PerPageRecord);
$query->limit(self::PerPageRecord);
}
$data['query'] = $query->toRawSql();
$data['list'] = $query->with([
'added_by', 'notification'
])->select("notified_users.*")->orderBy($sort_by, $sort_order)->get();
$data['next_offset'] = ((count($data['list']) == self::PerPageRecord) ? (isset($offset) ? ((int) $offset + 1) : 0) : -1);
return $data;
}
}