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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Enums\Setting\EntityType;
  6. use App\Models\Locale\City;
  7. use App\Models\Locale\Country;
  8. use App\Models\Locale\State;
  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. class CompanyProfile extends Model
  17. {
  18. use Blamable;
  19. use CompanyOwned;
  20. use HasFactory;
  21. protected $table = 'company_profiles';
  22. protected $fillable = [
  23. 'company_id',
  24. 'logo',
  25. 'address',
  26. 'city_id',
  27. 'zip_code',
  28. 'state_id',
  29. 'country',
  30. 'phone_number',
  31. 'email',
  32. 'tax_id',
  33. 'entity_type',
  34. 'created_by',
  35. 'updated_by',
  36. ];
  37. protected $casts = [
  38. 'entity_type' => EntityType::class,
  39. ];
  40. protected $appends = [
  41. 'logo_url',
  42. ];
  43. protected function logoUrl(): Attribute
  44. {
  45. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  46. if ($attributes['logo']) {
  47. return Storage::disk('public')->url($attributes['logo']);
  48. }
  49. return null;
  50. });
  51. }
  52. public function country(): BelongsTo
  53. {
  54. return $this->belongsTo(Country::class, 'country', 'id');
  55. }
  56. public function city(): BelongsTo
  57. {
  58. return $this->belongsTo(City::class, 'city_id', 'id');
  59. }
  60. public function state(): BelongsTo
  61. {
  62. return $this->belongsTo(State::class, 'state_id', 'id');
  63. }
  64. public function getCountryName(): string
  65. {
  66. return Country::findByIsoCode2($this->country)?->name ?? '';
  67. }
  68. protected static function newFactory(): Factory
  69. {
  70. return CompanyProfileFactory::new();
  71. }
  72. }