diff --git a/README.md b/README.md index 5d3e43a..235963e 100644 --- a/README.md +++ b/README.md @@ -31,27 +31,21 @@ And more on the way. ### install -`composer require lara-zeus/tartarus` -## setup +## Installations: -add locales to zeus-tartarus.php +- install laravel +- install filament +or use the [filament installer](https://github.com/lara-zeus/filament-installer) to install both together -```php -'locales' => [ - 'en' => ['name' => 'English', 'native' => 'English', 'regional' => 'en_GB', 'flag' => 'gb'], -], -``` -### Env: +- run `composer require lara-zeus/tartarus` +- run `php artisan tartarus:install ` +- run `php artisan migrate:fresh --seed` +- `npm i && npm run dev` +- login: email: `base@base.base` pass: `basebasebase` -`CENTRAL_DOMAIN=domain.test` -### config -- filament-logger.php: -```php - 'activity_resource' => \LaraZeus\Erebus\Filament\Clusters\Employees\Resources\ActivityResource::class, -``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on recent changes. diff --git a/composer.json b/composer.json index a3c29a4..68cc5c6 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "require": { "php": "^8.1", "awcodes/preset-color-picker": "^0.1.0", + "spatie/laravel-package-tools": "^1.16", "calebporzio/sushi": "^2.4", "filament/filament": "^3.2", "filament/spatie-laravel-translatable-plugin": "^3.2", @@ -35,7 +36,6 @@ "lara-zeus/erebus": "^1.0", "rickdbcn/filament-email": "^1.0", "ryangjchandler/blade-tabler-icons": "^2.3", - "spatie/laravel-package-tools": "^1.16", "spatie/laravel-tags": "^4.6", "stechstudio/filament-impersonate": "^3.7" }, diff --git a/composer.lock b/composer.lock index c4c6426..c35f7ff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "70e3bb9abff2c73fe9751c9c6f5e11dc", + "content-hash": "c4af19da0c9795a72a29b0753216692c", "packages": [ { "name": "anourvalar/eloquent-serialize", diff --git a/src/Configuration.php b/src/Configuration.php index e27d110..a532728 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -12,7 +12,7 @@ trait Configuration protected Closure | string $navigationGroupLabel = 'Tartarus'; protected array $tartarusModels = [ - //'Notification' => \LaraZeus\Tartarus\Models\Notification::class, + 'Company' => \LaraZeus\Tartarus\Models\Company::class, ]; public function navigationGroupLabel(Closure | string $label): static diff --git a/src/Filament/Clusters/System.php b/src/Filament/Clusters/System.php index c40f612..fde5099 100644 --- a/src/Filament/Clusters/System.php +++ b/src/Filament/Clusters/System.php @@ -3,7 +3,6 @@ namespace LaraZeus\Tartarus\Filament\Clusters; use Filament\Clusters\Cluster; -use Illuminate\Contracts\Support\Htmlable; class System extends Cluster { @@ -14,16 +13,6 @@ public static function getNavigationLabel(): string return __('app.System_cluster'); } - public function getTitle(): string | Htmlable - { - return __('app.System_cluster'); - } - - public function getHeading(): string | Htmlable - { - return __('app.System_cluster'); - } - public static function getClusterBreadcrumb(): ?string { return __('app.System_cluster'); diff --git a/src/Middleware/SetTenant.php b/src/Middleware/SetTenant.php index e7f0cf1..2951e8c 100644 --- a/src/Middleware/SetTenant.php +++ b/src/Middleware/SetTenant.php @@ -5,8 +5,8 @@ use Closure; use Filament\Support\Colors\Color; use Filament\Support\Facades\FilamentColor; -use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use LaraZeus\Tartarus\Models\Company; use Symfony\Component\HttpFoundation\Response; class SetTenant @@ -32,17 +32,19 @@ public function handle(Request $request, Closure $next): Response return $next($request); } - private function setPanelConfiguration(Model $tenant): void + private function setPanelConfiguration(Company $tenant): void { - $colorName = str($tenant->primary_color ?? 'Blue')->title(); - $color = constant("Filament\Support\Colors\Color::$colorName"); - FilamentColor::register([ - 'primary' => $color, - 'secondary' => Color::Amber, - 'danger' => Color::Red, - 'info' => Color::Blue, - 'success' => Color::Green, - 'warning' => Color::Yellow, - ]); + if ($tenant->primary_color !== null) { + $colorName = str($tenant->primary_color)->title(); + $color = constant("Filament\Support\Colors\Color::$colorName"); + FilamentColor::register([ + 'primary' => $color, + 'secondary' => Color::Amber, + 'danger' => Color::Red, + 'info' => Color::Blue, + 'success' => Color::Green, + 'warning' => Color::Yellow, + ]); + } } } diff --git a/src/Models/Company.php b/src/Models/Company.php index 98a2264..db22412 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -30,6 +30,12 @@ class Company extends Model implements HasAvatar, HasCurrentTenantLabel, HasName use CompanyRelations; use HasTranslations; + public function getTenantId(): ?string + { + // @phpstan-ignore-next-line + return auth()->user()?->company_id; + } + public array $translatable = ['name']; public function saveCompanySettings(array $data): void @@ -128,9 +134,12 @@ protected function defaultProfilePhotoUrl(): string return mb_substr($segment, 0, 1); })->join(' ')); - $colorName = str(tenant()->primary_color ?? 'Blue')->title(); - $color = constant("Filament\Support\Colors\Color::$colorName"); - $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', ''); + $bgColor = 'BFA577'; + if (tenant()->primary_color !== null) { + $colorName = str(tenant()->primary_color)->title(); + $color = constant("Filament\Support\Colors\Color::$colorName"); + $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', ''); + } return sprintf('https://ui-avatars.com/api/?name=%s&color=FFFFFF&background=' . $bgColor, urlencode($name)); } diff --git a/src/Models/CompanyInvitation.php b/src/Models/CompanyInvitation.php deleted file mode 100644 index b32ae4e..0000000 --- a/src/Models/CompanyInvitation.php +++ /dev/null @@ -1,13 +0,0 @@ -belongsTo(config('auth.providers.users.model'), 'user_id'); } - public function companyInvitations(): HasMany - { - return $this->hasMany(CompanyInvitation::class); - } - public function users(): BelongsToMany { return $this->belongsToMany(config('auth.providers.users.model'), Employeeship::class) diff --git a/src/Models/Concerns/HasCompanies.php b/src/Models/Concerns/HasCompanies.php index bc5586f..d3d7eeb 100644 --- a/src/Models/Concerns/HasCompanies.php +++ b/src/Models/Concerns/HasCompanies.php @@ -66,7 +66,7 @@ public function ownsCompany(?Model $company = null): bool return $this->id === $company->{$this->getForeignKey()}; } - public function belongsToCompany(?Company $company = null): bool + public function belongsToCompany(null | Company | Model $company = null): bool { if ($company === null) { return false; diff --git a/stubs/Models/User.php b/stubs/Models/User.php index f439e7b..4ef5aa0 100644 --- a/stubs/Models/User.php +++ b/stubs/Models/User.php @@ -20,7 +20,6 @@ use LaraZeus\Tartarus\Models\Concerns\HasCompanies; use LaraZeus\Tartarus\Models\ConnectedAccount; use LaraZeus\Tartarus\Models\Employeeship; -use Rinvex\Subscriptions\Traits\HasPlanSubscriptions; use Spatie\Color\Rgb; use Spatie\Permission\Models\Role; use Spatie\Permission\Traits\HasRoles; @@ -40,8 +39,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasDefaul use ChaosModel; use ForFilament; use HasCompanies; - - /*use HasPlanSubscriptions;*/ use HasRoles; use HasTranslations; use TwoFactorAuthenticatable; @@ -57,10 +54,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasDefaul 'email_verified_at' => 'datetime', ]; - /* * - * @var Company $tenant - */ - public function canAccessTenant(Model | Company $tenant): bool + public function canAccessTenant(null | Company | Model $tenant): bool { return $this->belongsToCompany($tenant); } @@ -83,7 +77,7 @@ protected function defaultProfilePhotoUrl(): string if (tenant() !== null) { $colorName = str(tenant()?->primary_color ?? 'Blue')->title(); $color = constant("Filament\Support\Colors\Color::$colorName"); - $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '') ?? $bgColor; + $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', ''); } return sprintf('https://ui-avatars.com/api/?name=%s&color=fff&background=' . $bgColor, urlencode($name)); diff --git a/stubs/config/app.php b/stubs/config/app.php new file mode 100644 index 0000000..b7f10cf --- /dev/null +++ b/stubs/config/app.php @@ -0,0 +1,195 @@ + env('APP_NAME', 'Laravel'), + + /* + |-------------------------------------------------------------------------- + | Application Environment + |-------------------------------------------------------------------------- + | + | This value determines the "environment" your application is currently + | running in. This may determine how you prefer to configure various + | services the application utilizes. Set this in your ".env" file. + | + */ + + 'env' => env('APP_ENV', 'production'), + + /* + |-------------------------------------------------------------------------- + | Application Debug Mode + |-------------------------------------------------------------------------- + | + | When your application is in debug mode, detailed error messages with + | stack traces will be shown on every error that occurs within your + | application. If disabled, a simple generic error page is shown. + | + */ + + 'debug' => (bool) env('APP_DEBUG', false), + + /* + |-------------------------------------------------------------------------- + | Application URL + |-------------------------------------------------------------------------- + | + | This URL is used by the console to properly generate URLs when using + | the Artisan command line tool. You should set this to the root of + | your application so that it is used when running Artisan tasks. + | + */ + + 'url' => env('APP_URL', 'http://localhost'), + + 'asset_url' => env('ASSET_URL'), + + /* + |-------------------------------------------------------------------------- + | Application Timezone + |-------------------------------------------------------------------------- + | + | Here you may specify the default timezone for your application, which + | will be used by the PHP date and date-time functions. We have gone + | ahead and set this to a sensible default for you out of the box. + | + */ + + 'timezone' => 'UTC', + + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ + + 'locale' => 'ar', + + 'locales' => [ + 'en' => ['name' => 'English', 'native' => 'English', 'regional' => 'en_GB', 'flag' => 'gb'], + ], + + /* + |-------------------------------------------------------------------------- + | Application Fallback Locale + |-------------------------------------------------------------------------- + | + | The fallback locale determines the locale to use when the current one + | is not available. You may change the value to correspond to any of + | the language folders that are provided through your application. + | + */ + + 'fallback_locale' => 'ar', + + /* + |-------------------------------------------------------------------------- + | Faker Locale + |-------------------------------------------------------------------------- + | + | This locale will be used by the Faker PHP library when generating fake + | data for your database seeds. For example, this will be used to get + | localized telephone numbers, street address information and more. + | + */ + + 'faker_locale' => 'en_US', + + /* + |-------------------------------------------------------------------------- + | Encryption Key + |-------------------------------------------------------------------------- + | + | This key is used by the Illuminate encrypter service and should be set + | to a random, 32 character string, otherwise these encrypted strings + | will not be safe. Please do this before deploying an application! + | + */ + + 'key' => env('APP_KEY'), + + 'cipher' => 'AES-256-CBC', + + /* + |-------------------------------------------------------------------------- + | Maintenance Mode Driver + |-------------------------------------------------------------------------- + | + | These configuration options determine the driver used to determine and + | manage Laravel's "maintenance mode" status. The "cache" driver will + | allow maintenance mode to be controlled across multiple machines. + | + | Supported drivers: "file", "cache" + | + */ + + 'maintenance' => [ + 'driver' => 'file', + // 'store' => 'redis', + ], + + /* + |-------------------------------------------------------------------------- + | Autoloaded Service Providers + |-------------------------------------------------------------------------- + | + | The service providers listed here will be automatically loaded on the + | request to your application. Feel free to add your own services to + | this array to grant expanded functionality to your applications. + | + */ + + 'providers' => ServiceProvider::defaultProviders()->merge([ + /* + * Package Service Providers... + */ + + /* + * Application Service Providers... + */ + App\Providers\AppServiceProvider::class, + App\Providers\AuthServiceProvider::class, + // App\Providers\BroadcastServiceProvider::class, + App\Providers\EventServiceProvider::class, + App\Providers\RouteServiceProvider::class, + App\Providers\Filament\AdminPanelProvider::class, + App\Providers\Filament\CompanyPanelProvider::class, + App\Providers\Filament\UserPanelProvider::class, + ])->toArray(), + + /* + |-------------------------------------------------------------------------- + | Class Aliases + |-------------------------------------------------------------------------- + | + | This array of class aliases will be registered when this application + | is started. However, feel free to register as many as you wish as + | the aliases are "lazy" loaded so they don't hinder performance. + | + */ + + 'aliases' => Facade::defaultAliases()->merge([ + // 'Example' => App\Facades\Example::class, + ])->toArray(), + +];