Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CompanyProfile.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if ($attributes['logo']) {
  48. return Storage::disk('public')->url($attributes['logo']);
  49. }
  50. return null;
  51. });
  52. }
  53. public function company(): BelongsTo
  54. {
  55. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  56. }
  57. public function country(): BelongsTo
  58. {
  59. return $this->belongsTo(Country::class, 'country', 'id');
  60. }
  61. public function city(): BelongsTo
  62. {
  63. return $this->belongsTo(City::class, 'city_id', 'id');
  64. }
  65. public function state(): BelongsTo
  66. {
  67. return $this->belongsTo(State::class, 'state_id', 'id');
  68. }
  69. public function createdBy(): BelongsTo
  70. {
  71. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  72. }
  73. public function updatedBy(): BelongsTo
  74. {
  75. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  76. }
  77. public function getCountryName(): string
  78. {
  79. return Country::findByIsoCode2($this->country)?->name ?? '';
  80. }
  81. protected static function newFactory(): Factory
  82. {
  83. return CompanyProfileFactory::new();
  84. }
  85. }