69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\TicketStatusFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
#[Fillable(['board_column_id', 'name', 'position', 'project_id', 'slug'])]
|
|
class TicketStatus extends Model
|
|
{
|
|
/** @use HasFactory<TicketStatusFactory> */
|
|
use HasFactory;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (self $ticketStatus): void {
|
|
$ticketStatus->slug = Str::slug($ticketStatus->name);
|
|
});
|
|
}
|
|
|
|
public function allowedSourceStatuses(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
self::class,
|
|
'ticket_status_transitions',
|
|
'to_ticket_status_id',
|
|
'from_ticket_status_id',
|
|
)
|
|
->orderBy('board_column_id')
|
|
->orderBy('position')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function allowedTargetStatuses(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
self::class,
|
|
'ticket_status_transitions',
|
|
'from_ticket_status_id',
|
|
'to_ticket_status_id',
|
|
)
|
|
->orderBy('board_column_id')
|
|
->orderBy('position')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function boardColumn(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BoardColumn::class);
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function tickets(): HasMany
|
|
{
|
|
return $this->hasMany(Ticket::class)
|
|
->orderByDesc('sequence_number');
|
|
}
|
|
}
|