FinancialPlanAccount.php 2.8 KB

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