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.

ConnectedBankAccount.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Enums\BankAccountType;
  4. use App\Traits\Blamable;
  5. use App\Traits\CompanyOwned;
  6. use Illuminate\Database\Eloquent\Casts\Attribute;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  9. use Wallo\FilamentCompanies\FilamentCompanies;
  10. class ConnectedBankAccount extends Model
  11. {
  12. use Blamable;
  13. use CompanyOwned;
  14. protected $table = 'connected_bank_accounts';
  15. protected $fillable = [
  16. 'company_id',
  17. 'institution_id',
  18. 'bank_account_id',
  19. 'external_account_id',
  20. 'access_token',
  21. 'identifier',
  22. 'item_id',
  23. 'currency_code',
  24. 'current_balance',
  25. 'name',
  26. 'mask',
  27. 'type',
  28. 'subtype',
  29. 'import_transactions',
  30. 'created_by',
  31. 'updated_by',
  32. ];
  33. protected $casts = [
  34. 'import_transactions' => 'boolean',
  35. 'type' => BankAccountType::class,
  36. 'access_token' => 'encrypted',
  37. ];
  38. protected $appends = [
  39. 'masked_number',
  40. ];
  41. public function company(): BelongsTo
  42. {
  43. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  44. }
  45. public function institution(): BelongsTo
  46. {
  47. return $this->belongsTo(Institution::class, 'institution_id');
  48. }
  49. public function bankAccount(): BelongsTo
  50. {
  51. return $this->belongsTo(BankAccount::class, 'bank_account_id');
  52. }
  53. protected function maskedNumber(): Attribute
  54. {
  55. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  56. return $attributes['mask'] ? '•••• ' . substr($attributes['mask'], -4) : null;
  57. });
  58. }
  59. public function createdBy(): BelongsTo
  60. {
  61. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  62. }
  63. public function updatedBy(): BelongsTo
  64. {
  65. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  66. }
  67. }