diff --git a/README.md b/README.md index 4da8b71..f9c102f 100644 --- a/README.md +++ b/README.md @@ -314,49 +314,6 @@ you can allow the contact us manager by using this code ) ``` -## Allow Teams Manager - -install jetstream without run install command. - -```bash -composer require laravel/jetstream -``` - -than publish the migrations - -```bash -php artisan vendor:publish --tag=filament-accounts-teams-migrations -``` - -now you need to migrate your database - -```bash -php artisan migrate -``` - -now publish your Accounts model - -```bash -php artisan vendor:publish --tag="filament-accounts-model" -``` - -inside your published model use this implementation - -```php -class Account extends Authenticatable implements HasMedia, FilamentUser, HasAvatar, HasTenants, HasDefaultTenant -{ - ... - use InteractsWithTenant; -} -``` - -on your main panel you must use teams - -```php -->plugin(\TomatoPHP\FilamentAccounts\FilamentAccountsPlugin::make() - ->useTeams() -) -``` ## Attach New Field To Accounts @@ -469,7 +426,48 @@ you can activate or deactivate any feature you want from the package config file ![Invite Team](https://raw.githubusercontent.com/tomatophp/filament-accounts/master/arts/invite-team.png) ![API Tokens](https://raw.githubusercontent.com/tomatophp/filament-accounts/master/arts/api-tokens.png) -install jetstream without install it. +now publish your Accounts model + +```bash +php artisan vendor:publish --tag="filament-accounts-model" +``` + +on your main panel you must use login functions + +```php +->plugin(\TomatoPHP\FilamentAccounts\FilamentAccountsPlugin::make() + ... + ->canLogin() + ->canBlocked() +) +``` + + +now on your new panel just use this plugin + +```php +->plugin( + FilamentAccountsSaaSPlugin::make() + ->databaseNotifications() + ->checkAccountStatusInLogin() + ->APITokenManager() + ->editProfile() + ->editPassword() + ->browserSesstionManager() + ->deleteAccount() + ->editProfileMenu() + ->registration() + ->useOTPActivation(), +) +``` + +you can change settings by remove just methods from plugin. + +**NOTE** to use `->useOTPActivation()` you need to install [Filament Alets](https://github.com/tomatophp/filament-alets) from the next step first, and to use `->databaseNotifications()` you need to publish notification database table first + +## Allow Teams Manager + +install jetstream without run install command. ```bash composer require laravel/jetstream @@ -507,40 +505,22 @@ on your main panel you must use teams ```php ->plugin(\TomatoPHP\FilamentAccounts\FilamentAccountsPlugin::make() - ... - ->canLogin() - ->canBlocked() ->useTeams() ) ``` - -now on your new panel just use this plugin +and on your app panel you must use this plugin ```php -->plugin( - FilamentAccountsSaaSPlugin::make() - ->databaseNotifications() - ->checkAccountStatusInLogin() - ->APITokenManager() +->plugin(\TomatoPHP\FilamentAccounts\FilamentAccountsSaaSPlugin::make() ->editTeam() ->deleteTeam() ->teamInvitation() ->showTeamMembers() - ->editProfile() - ->editPassword() - ->browserSesstionManager() - ->deleteAccount() - ->editProfileMenu() - ->registration() - ->useOTPActivation(), + ->allowTenants() ) ``` -you can change settings by remove just methods from plugin. - -**NOTE** to use `->useOTPActivation()` you need to install [Filament Alets](https://github.com/tomatophp/filament-alets) from the next step first, and to use `->databaseNotifications()` you need to publish notification database table first - ### Use Account Locations on SaaS Panel you can make your account manage the locations by using this code diff --git a/publish/Account.php b/publish/Account.php index bc833b4..1fa222c 100644 --- a/publish/Account.php +++ b/publish/Account.php @@ -42,12 +42,11 @@ * @property Model meta($key, $value) * @property Location[] $locations */ -class Account extends Authenticatable implements HasMedia, HasAvatar, HasTenants +class Account extends Authenticatable implements HasMedia, HasAvatar { use InteractsWithMedia; use HasApiTokens, HasFactory, Notifiable; use SoftDeletes; - use InteractsWithTenant; /** * @var array @@ -136,10 +135,10 @@ public function accountsMetas(): \Illuminate\Database\Eloquent\Relations\HasMany /** * @param string $key - * @param string|array|object|null $value - * @return Model|string|array|null + * @param mixed $value + * @return mixed */ - public function meta(string $key, string|array|object|null $value=null): Model|string|null|array + public function meta(string $key, mixed $value=null): mixed { if($value!==null){ if($value === 'null'){ diff --git a/src/FilamentAccountsSaaSPlugin.php b/src/FilamentAccountsSaaSPlugin.php index 9b6a70f..d35bf18 100644 --- a/src/FilamentAccountsSaaSPlugin.php +++ b/src/FilamentAccountsSaaSPlugin.php @@ -34,9 +34,11 @@ public function getId(): string public function register(Panel $panel): void { - $panel - ->tenant($this->useJetstreamTeamModel ? Jetstream::teamModel(): Team::class, 'id') - ->tenantRegistration(CreateTeam::class); + if($this->allowTenants){ + $panel + ->tenant($this->useJetstreamTeamModel ? Jetstream::teamModel(): Team::class, 'id') + ->tenantRegistration(CreateTeam::class); + } $pages = [ CreateTeam::class @@ -52,10 +54,12 @@ public function register(Panel $panel): void $pages[] = EditProfile::class; if($this->editProfileMenu){ - $menuItems[] = MenuItem::make() - ->label(fn(): string => EditProfile::getNavigationLabel()) - ->icon('heroicon-s-user') - ->url(fn (): string => EditProfile::getUrl()); + $panel->userMenuItems([ + "profile" => MenuItem::make() + ->label(fn(): string => auth('accounts')->user()?->name) + ->icon('heroicon-s-user') + ->url(fn (): string => EditProfile::getUrl()) + ]); } } @@ -132,6 +136,7 @@ public function register(Panel $panel): void public bool $useJetstreamTeamModel = false; public bool $teamInvitation = false; public bool $deleteTeam = false; + public bool $allowTenants = false; public bool $showTeamMembers = false; public bool $checkAccountStatusInLogin = false; public bool $useOTPActivation = false; @@ -141,6 +146,12 @@ public function register(Panel $panel): void public bool $showContactUsButton = false; public bool $useTypes = false; + public function allowTenants(bool $allowTenants = true): static + { + $this->allowTenants = $allowTenants; + return $this; + } + public function useTypes(bool $useTypes = true): static { $this->useTypes = $useTypes; diff --git a/src/Models/Account.php b/src/Models/Account.php index 2844c9d..2b26f40 100644 --- a/src/Models/Account.php +++ b/src/Models/Account.php @@ -133,10 +133,10 @@ public function accountsMetas(): \Illuminate\Database\Eloquent\Relations\HasMany /** * @param string $key - * @param string|array|object|null $value - * @return Model|string|array|null + * @param mixed $value + * @return mixed */ - public function meta(string $key, string|array|object|null $value=null): Model|string|null|array + public function meta(string $key, mixed $value=null): mixed { if($value!==null){ if($value === 'null'){