Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ConnectedBankAccount.php 1.9KB

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