-
-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need this for Multi-Tenancy (Teams) #819
Comments
Currently work around by creating wallet before calling deposit().
And in the config file config/wallet.php, I set default with team_id, so it won't cause error if wallet was not initially created before use.
I hope there is a better way to hook it in the future version. |
Hello. I didn't use this functionality, there was no need. I'll think about a solution in my free time |
@zenepay I was thinking, then why do you need to link a wallet to a specific user? Link wallets to your team. Then you will have code something like this: use Bavix\Wallet\Traits\HasWallets;
use Bavix\Wallet\Interfaces\Wallet;
class Team extends \Laravel\Jetstream\Team implements Wallet
{
use HasWallets;
} Then: $user-> currentTeam->createWallet(...);
$user-> currentTeam-> hasWallet('my-wallet'); |
There is no problem if creating wallet manually using createWallet(), since we can assign team_id with some way. But if using default wallet by just call $user->deposit(10) where the wallet was not initially created, it will fail since it requires team_id to save to database table wallets. So, I wonder that how I could listen to event creating of the wallet when calling via deposit(). I cannot modify wallets.team_id before it saving to db. |
Thank you. Please,:) it will be high benefit for SaaS projects. |
The default wallet is only needed in very simple projects. In your case, you need to use multi-wallets.
The package has its own events.
You can follow the example from unit tests and add additional fields through meta data and save them in separate fields. Although the example is for transactions, it is also perfect for wallets: laravel-wallet/tests/Units/Domain/WalletExtensionTest.php Lines 23 to 33 in eb3862d
|
@zenepay starting from tag 10.1.0 you can used method getDynamicDefaultSlug in model. final class User extends Model implements Wallet
{
use HasWallet;
public function getDynamicDefaultSlug(): string
{
return $this->current_team_id.'-my-wallet';
}
} Release today, but later. |
When implementing with Teams, a user may belong to many teams, a wallet should belong to a team.
Then the wallet table may have team_id as a forieng key. The model Wallet then should BelongsTo a team.
I am trying to inject the team_id value when calling deposit() by lisening to event Wallet creating() in the boot(), unfortunately, deposit() does not dispatch the event creating to wallet. I cannot set team_id before the transaction creating a new wallet.
Please advise, or have this Team feature for new version.
The text was updated successfully, but these errors were encountered: