Tenant.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Scopes\TenantEnvScope;
  4. use Encore\Admin\Traits\DefaultDatetimeFormat;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use Stancl\Tenancy\Database\Concerns\HasDatabase;
  7. use Stancl\Tenancy\Database\Concerns\HasDomains;
  8. use Stancl\Tenancy\Database\Models\Tenant as BaseTenant;
  9. use Stancl\Tenancy\Contracts\TenantWithDatabase;
  10. /**
  11. * @method __call(string $method, array $parameters)
  12. * @method __callStatic(string $method, array $parameters)
  13. */
  14. class Tenant extends BaseTenant implements TenantWithDatabase
  15. {
  16. use HasDatabase, HasDomains;
  17. use DefaultDatetimeFormat;
  18. public function users(): HasMany
  19. {
  20. return $this->hasMany(GlobalUser::class, 'tenant_id');
  21. }
  22. protected static function booted(): void
  23. {
  24. if (php_sapi_name() === 'cli') {
  25. static::addGlobalScope(new TenantEnvScope());
  26. }
  27. }
  28. protected $casts = [
  29. ];
  30. public static function getCustomColumns(): array
  31. {
  32. return [
  33. 'id',
  34. 'name',
  35. 'email',
  36. 'company_name',
  37. 'expired_at',
  38. 'env'
  39. ];
  40. }
  41. }