added support ticket and added more stat widgets

This commit is contained in:
Gitea
2025-05-17 05:11:29 +05:30
parent f30d7fa096
commit 175a7203f3
19 changed files with 975 additions and 6 deletions

57
app/Models/Ticket.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ticket extends Model
{
use HasFactory;
protected $fillable = [
'user_id', 'ticket_id', 'subject', 'message', 'status', 'last_response_at', 'ip_address'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function responses()
{
return $this->hasMany(TicketResponse::class);
}
protected $casts = [
'created_at' => 'datetime', // Ensures created_at is a Carbon instance
'updated_at' => 'datetime', // Ensures updated_at is a Carbon instance
'last_response_at' => 'datetime', // Cast last_response_at to Carbon instance
];
public static function autoClose(): bool
{
try {
$tickets = Ticket::where('status', 'pending')
->where('last_response_at', '<', now()->subDays(3))
->get();
if (count($tickets) > 0) {
foreach ($tickets as $ticket) {
$ticket->status = 'closed';
$ticket->save();
TicketResponse::create([
'ticket_id' => $ticket->id,
'user_id' => 1,
'response' => 'This ticket has been auto-closed due to inactivity.',
]);
}
}
return true;
} catch (\Exception $e) {
return false;
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TicketResponse extends Model
{
use HasFactory;
protected $fillable = [
'ticket_id', 'user_id', 'response', 'ip_address'
];
public function ticket()
{
return $this->belongsTo(Ticket::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@@ -6,6 +6,7 @@ namespace App\Models;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
@@ -63,4 +64,9 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
return str_ends_with($this->email, '@zemail.me') && $this->level === 9 && $this->hasVerifiedEmail();
}
public function tickets(): HasMany
{
return $this->hasMany(Ticket::class);
}
}