dstpabuaran.com/app/Models/Category.php
Yoga Pangestu 5961a60585 feat: add labels and formatting attributes to various models and enums
- Added labels for leave request statuses in LeaveRequestStatus enum.
- Introduced label methods for PayrollAdjustmentType, PayrollPeriodStatus, PayrollStatus, RawMaterialUnit, and StokOpnameStatus enums.
- Implemented formatted attributes for Attendance, CashAccount, CashTransaction, Category, Customer, Cutting, Employee, EmployeeAdvance, Expense, LeaveRequest, Order, OrderItem, Payroll, PayrollAdjustment, PayrollPeriod, Product, ProductPrice, ProductVariant, Purchase, PurchaseItem, RawMaterial, RawMaterialPrice, Restock, RestockItem, StokOpname, StokOpnameItem, Supplier, User, and UserProfile models.
- Enhanced phone number formatting for Customer and Supplier models.
- Added date formatting for various models to improve readability.
2026-08-04 15:31:41 +07:00

34 lines
916 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Appends;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Sluggable\Attributes\Sluggable;
#[Appends(['formatted_name'])]
#[Guarded(['id'])]
#[Sluggable(from: 'name', to: 'slug')]
class Category extends Model
{
use HasFactory, SoftDeletes;
protected function formattedName(): Attribute
{
return Attribute::make(
get: fn () => ucfirst($this->name),
);
}
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'product_categories')
->using(ProductCategory::class);
}
}