選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ConnectedBankAccount.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Enums\BankAccountType;
  4. use App\Models\Accounting\Account;
  5. use App\Traits\Blamable;
  6. use App\Traits\CompanyOwned;
  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. 'created_by',
  32. 'updated_by',
  33. ];
  34. protected $casts = [
  35. 'import_transactions' => 'boolean',
  36. 'type' => BankAccountType::class,
  37. 'access_token' => 'encrypted',
  38. ];
  39. protected $appends = [
  40. 'masked_number',
  41. ];
  42. public function institution(): BelongsTo
  43. {
  44. return $this->belongsTo(Institution::class, 'institution_id');
  45. }
  46. public function bankAccount(): BelongsTo
  47. {
  48. return $this->belongsTo(BankAccount::class, 'bank_account_id');
  49. }
  50. public function account(): HasOneThrough
  51. {
  52. return $this->hasOneThrough(
  53. Account::class,
  54. BankAccount::class,
  55. 'id',
  56. 'accountable_id',
  57. 'bank_account_id',
  58. 'id'
  59. );
  60. }
  61. protected function maskedNumber(): Attribute
  62. {
  63. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  64. return $attributes['mask'] ? '•••• ' . substr($attributes['mask'], -4) : null;
  65. });
  66. }
  67. }