41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable(['category_id', 'name', 'description', 'default_priority_key'])]
|
|
class Subcategory extends Model
|
|
{
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function customFields(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(CustomField::class, 'custom_field_subcategory')
|
|
->withPivot('position')
|
|
->orderBy('custom_field_subcategory.position');
|
|
}
|
|
|
|
public function teams(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Team::class, 'team_subcategory');
|
|
}
|
|
|
|
public function tickets(): HasMany
|
|
{
|
|
return $this->hasMany(Ticket::class);
|
|
}
|
|
|
|
public function label(): string
|
|
{
|
|
return $this->category->name.' / '.$this->name;
|
|
}
|
|
}
|