FinancialPlanAccount.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * @property int $id
  8. * @property int|null $unit_id
  9. * @property string $code
  10. * @property string $order
  11. * @property string $description
  12. * @property string $chart_type
  13. * @property \Illuminate\Support\Carbon|null $created_at
  14. * @property \Illuminate\Support\Carbon|null $updated_at
  15. * @property \Illuminate\Support\Carbon|null $deleted_at
  16. * @property int|null $parent_id
  17. * @property-read \Illuminate\Database\Eloquent\Collection<int, FinancialPlanAccount> $children
  18. * @property-read int|null $children_count
  19. * @property-read FinancialPlanAccount|null $parent
  20. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount newModelQuery()
  21. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount newQuery()
  22. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount onlyTrashed()
  23. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount query()
  24. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereChartType($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereCode($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereCreatedAt($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereDeletedAt($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereDescription($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereId($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereOrder($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereParentId($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereUnitId($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount whereUpdatedAt($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount withTrashed(bool $withTrashed = true)
  35. * @method static \Illuminate\Database\Eloquent\Builder<static>|FinancialPlanAccount withoutTrashed()
  36. * @mixin \Eloquent
  37. */
  38. class FinancialPlanAccount extends Model
  39. {
  40. use HasFactory, SoftDeletes;
  41. protected $table = 'financial_plan_accounts';
  42. protected $guarded = [
  43. 'id', // Add more fields that shouldn't be edited here
  44. ];
  45. protected $casts = [
  46. 'created_at' => 'datetime',
  47. 'updated_at' => 'datetime',
  48. 'deleted_at' => 'datetime',
  49. ];
  50. // Relationships
  51. public function parent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  52. {
  53. return $this->belongsTo(self::class, 'parent_id');
  54. }
  55. public function children(): \Illuminate\Database\Eloquent\Relations\HasMany
  56. {
  57. return $this->hasMany(self::class, 'parent_id');
  58. }
  59. // Business Logic Methods
  60. /** Conta raiz (sem pai). */
  61. public function isRoot(): bool
  62. {
  63. return $this->parent_id === null;
  64. }
  65. // Custom Finders
  66. // Query Scopes
  67. }