Refactor models.

This commit is contained in:
James Cole
2025-09-14 09:00:01 +02:00
parent 935453796e
commit 9d9483e20f
46 changed files with 688 additions and 676 deletions

View File

@@ -37,6 +37,7 @@ class ObjectGroup extends Model
{
use ReturnsIntegerIdTrait;
use ReturnsIntegerUserIdTrait;
protected $fillable = ['title', 'order', 'user_id', 'user_group_id'];
/**
@@ -47,12 +48,11 @@ class ObjectGroup extends Model
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$objectGroupId = (int) $value;
$objectGroupId = (int)$value;
/** @var null|ObjectGroup $objectGroup */
$objectGroup = self::where('object_groups.id', $objectGroupId)
->where('object_groups.user_id', auth()->user()->id)->first()
;
$objectGroup = self::where('object_groups.id', $objectGroupId)
->where('object_groups.user_id', auth()->user()->id)->first();
if (null !== $objectGroup) {
return $objectGroup;
}
@@ -90,13 +90,6 @@ class ObjectGroup extends Model
return $this->morphedByMany(PiggyBank::class, 'object_groupable');
}
protected function order(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function casts(): array
{
return [
@@ -107,4 +100,11 @@ class ObjectGroup extends Model
'deleted_at' => 'datetime',
];
}
protected function order(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
}