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.

CompanyProfile.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Enums\EntityType;
  4. use App\Models\Locale\City;
  5. use App\Models\Locale\Country;
  6. use App\Models\Locale\State;
  7. use App\Traits\Blamable;
  8. use App\Traits\CompanyOwned;
  9. use Database\Factories\Setting\CompanyProfileFactory;
  10. use Illuminate\Database\Eloquent\Casts\Attribute;
  11. use Illuminate\Database\Eloquent\Factories\Factory;
  12. use Illuminate\Database\Eloquent\Factories\HasFactory;
  13. use Illuminate\Database\Eloquent\Model;
  14. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  15. use Illuminate\Support\Facades\Storage;
  16. use Wallo\FilamentCompanies\FilamentCompanies;
  17. class CompanyProfile extends Model
  18. {
  19. use Blamable;
  20. use CompanyOwned;
  21. use HasFactory;
  22. protected $table = 'company_profiles';
  23. protected $fillable = [
  24. 'company_id',
  25. 'logo',
  26. 'address',
  27. 'city_id',
  28. 'zip_code',
  29. 'state_id',
  30. 'country',
  31. 'phone_number',
  32. 'email',
  33. 'tax_id',
  34. 'entity_type',
  35. 'created_by',
  36. 'updated_by',
  37. ];
  38. protected $casts = [
  39. 'entity_type' => EntityType::class,
  40. ];
  41. protected $appends = [
  42. 'logo_url',
  43. ];
  44. protected function logoUrl(): Attribute
  45. {
  46. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  47. return $attributes['logo'] ? Storage::disk('public')->url($attributes['logo']) : null;
  48. });
  49. }
  50. public function company(): BelongsTo
  51. {
  52. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  53. }
  54. public function country(): BelongsTo
  55. {
  56. return $this->belongsTo(Country::class, 'country', 'id');
  57. }
  58. public function city(): BelongsTo
  59. {
  60. return $this->belongsTo(City::class, 'city_id', 'id');
  61. }
  62. public function state(): BelongsTo
  63. {
  64. return $this->belongsTo(State::class, 'state_id', 'id');
  65. }
  66. public function createdBy(): BelongsTo
  67. {
  68. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  69. }
  70. public function updatedBy(): BelongsTo
  71. {
  72. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  73. }
  74. public function getCountryName(): string
  75. {
  76. return Country::findByIsoCode2($this->country)?->name ?? '';
  77. }
  78. protected static function newFactory(): Factory
  79. {
  80. return CompanyProfileFactory::new();
  81. }
  82. }