<?php
 namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; class AiTrainingDataset extends Model { use SoftDeletes; protected $fillable = [ 'name', 'description', 'type', 'status', 'item_count', 'created_by', ]; public function items(): HasMany { return $this->hasMany(AiTrainingItem::class, 'dataset_id'); } public function approvedItems(): HasMany { return $this->hasMany(AiTrainingItem::class, 'dataset_id')->where('approved', true); } public function creator(): BelongsTo { return $this->belongsTo(Admin::class, 'created_by'); } public function updateItemCount(): void { $this->update(['item_count' => $this->approvedItems()->count()]); } } 