whisper-money/app/Models/Label.php

56 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\BelongsToSpace;
use Database\Factories\LabelFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
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\SoftDeletes;
class Label extends Model
{
/** @use HasFactory<LabelFactory> */
use BelongsToSpace, HasFactory, HasUuids, SoftDeletes;
protected $fillable = [
'name',
'color',
'user_id',
'space_id',
];
/**
* Hide the pivot from serialization so a Label looks identical whether it
* is loaded standalone or through a belongsToMany relation.
*
* @var list<string>
*/
protected $hidden = [
'pivot',
'space_id',
];
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function transactions(): BelongsToMany
{
return $this->belongsToMany(Transaction::class)
->using(LabelTransaction::class)
->withTimestamps();
}
public function automationRules(): BelongsToMany
{
return $this->belongsToMany(AutomationRule::class, 'automation_rule_labels')
->using(AutomationRuleLabel::class);
}
}