You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Category.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Models\Document\Document;
  4. use App\Models\Item;
  5. use Database\Factories\CategoryFactory;
  6. use Illuminate\Database\Eloquent\Factories\Factory;
  7. use Illuminate\Database\Eloquent\Factories\HasFactory;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\HasMany;
  11. use Wallo\FilamentCompanies\FilamentCompanies;
  12. class Category extends Model
  13. {
  14. use HasFactory;
  15. protected $table = 'categories';
  16. protected $fillable = [
  17. 'company_id',
  18. 'name',
  19. 'type',
  20. 'color',
  21. 'enabled',
  22. 'created_by',
  23. ];
  24. protected $casts = [
  25. 'enabled' => 'boolean',
  26. ];
  27. public function company(): BelongsTo
  28. {
  29. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  30. }
  31. public function createdBy(): BelongsTo
  32. {
  33. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  34. }
  35. public function items(): HasMany
  36. {
  37. return $this->hasMany(Item::class);
  38. }
  39. public function documents(): HasMany
  40. {
  41. return $this->hasMany(Document::class);
  42. }
  43. public function bills(): HasMany
  44. {
  45. return $this->documents()->where('type', 'bill');
  46. }
  47. public function invoices(): HasMany
  48. {
  49. return $this->documents()->where('type', 'invoice');
  50. }
  51. protected static function newFactory(): Factory
  52. {
  53. return CategoryFactory::new();
  54. }
  55. }