You've already forked Atomcms-edit
574b5d6e17
feat: add 24 model factories for Help, Shop, Community, Game, User domains - Translate mixed Dutch/English strings in README.md and AlertSettings.php - Add HasFactory trait to 23 models - Create factories for Help (6), Shop (4), Community (5), Game (2), User (7)
86 lines
2.6 KiB
PHP
Executable File
86 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models\Help;
|
|
|
|
use App\Models\Concerns\BelongsToUser;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Stevebauman\Purify\Facades\Purify;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $category_id
|
|
* @property string $subject
|
|
* @property string $content
|
|
* @property int $severity
|
|
* @property bool $open
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property-read string $content
|
|
* @property-read User|null $user
|
|
* @property-read WebsiteHelpCenterCategory|null $category
|
|
* @property-read Collection<int, WebsiteHelpCenterTicketReply> $replies
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket orderBy($column, $direction = 'asc')
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket where($column, $operator = null, $value = null)
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket get($columns = ['*'])
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
|
*/
|
|
class WebsiteHelpCenterTicket extends Model
|
|
{
|
|
use BelongsToUser;
|
|
use HasFactory;
|
|
|
|
#[\Override]
|
|
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'status', 'subject', 'category_id'];
|
|
|
|
/** @var array<int, string> */
|
|
#[\Override]
|
|
protected $with = ['user', 'category'];
|
|
|
|
#[\Override]
|
|
public $timestamps = false;
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WebsiteHelpCenterCategory::class);
|
|
}
|
|
|
|
public function replies(): HasMany
|
|
{
|
|
return $this->hasMany(WebsiteHelpCenterTicketReply::class, 'ticket_id')->latest();
|
|
}
|
|
|
|
public function canDeleteTicket()
|
|
{
|
|
return $this->user_id === Auth::id() || hasPermission('delete_website_tickets');
|
|
}
|
|
|
|
public function canManageTicket()
|
|
{
|
|
return $this->user_id === Auth::id() || hasPermission('manage_website_tickets');
|
|
}
|
|
|
|
public function canCloseTicket()
|
|
{
|
|
return $this->user_id === Auth::id() || hasPermission('manage_website_tickets');
|
|
}
|
|
|
|
public function isOpen()
|
|
{
|
|
return $this->open || hasPermission('manage_website_tickets');
|
|
}
|
|
|
|
public function getContentAttribute($value)
|
|
{
|
|
return Purify::clean($value);
|
|
}
|
|
}
|