Skip to content

Commit

Permalink
remove multi tenants from SaaS panel and add it as option
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Oct 9, 2024
1 parent 44cffb7 commit b589e84
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 80 deletions.
110 changes: 45 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions publish/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'){
Expand Down
25 changes: 18 additions & 7 deletions src/FilamentAccountsSaaSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
]);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down

0 comments on commit b589e84

Please sign in to comment.