-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat: updateOrAddMeta for wallet #767
Conversation
It will be nice to have a method that updates or adds a new key to the meta. Just like what you did here: bavix#498 (comment) Signed-off-by: Kekeocha Justin Chetachukwu <[email protected]>
changed variable name Signed-off-by: Kekeocha Justin Chetachukwu <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #767 +/- ##
=============================================
- Coverage 100.00% 99.89% -0.11%
- Complexity 551 552 +1
=============================================
Files 83 83
Lines 1946 1948 +2
=============================================
Hits 1946 1946
- Misses 0 2 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thank you for your contribution to the project, but I can't add this feature to the wallet model. This functionality should be located in the area of the team that is developing its software product. Here's how to define replace or merge at the package level? How to solve a problem with a depth greater than 1? In addition, the name of the method is not correct. By update, people understand an sql operation, because this method is in the model. Here is a small example for you: $meta = [
'order' => [
'id' => '92e330ec-c248-48a7-b7c2-a7d48535e417',
'items' => [1,2,3,4,15],
],
];
$meta = array_merge($meta, [
'order' => [
'title' => 'Message',
],
]);
/*
array(1) {
["order"]=>
array(1) {
["title"]=>
string(7) "Message"
}
}
*/ |
The code above does not remove existing records when saved if that is what you mean. Maybe you should actually run the method. |
I see and understand, I'm talking about the name and area of responsibility. The formation of a meta array is not the responsibility of the package. |
Name can be changed to what will best describe it. I was just trying to add more helpers like the Eloquent updateOrCreate() method. |
I understand, but this is not the responsibility of the package. Here you need to approach conservatively, according to the principle of YAGNI (You Aren't Gonna Need It). The package develops from the feedback received, this functionality is superfluous. The more functions we add, the more difficult and expensive refactoring is. As part of the package, we do not solve the problems that developers have with php. Here we are developing an API for working on the wallet. If you are looking for useful functionality, then please develop the balance with credit method. The point is to display the full balance along with the credit limit. You can read about the functionality here: https://bavix.github.io/laravel-wallet/#/credit-limits UPD: Only necessarily new functionality must be covered by unit tests. |
I tried that, but it didn't work, which was was what set me searching. |
Sorry, I didn't catch the context. Can you tell me more about what you're talking about? |
Quick question: supposing I want to extend the wallet.php model to add the feature for my own custom app. How would I do this. From going through the codebase, the MorphOne trait, has a wallet method which calls the wallet model. The getWalletAttribute() also calls a CastServiceInterface. But I couldn't find a way to extend the model. |
@justinkekeocha You need to expand the model and replace it through the config. laravel-wallet/config/config.php Line 184 in 9b0bd38
Example use Bavix\Wallet\Models\Wallet as WalletBase;
class MyWallet extends WalletBase {
public function helloWorld(): string { return "hello world"; }
}
...
'wallet' => [
'table' => 'wallets',
'model' => MyWallet::class,
'creating' => [],
'default' => [
'name' => 'Default Wallet',
'slug' => 'default',
'meta' => [],
],
],
... echo $user->wallet->helloWorld(); UPD: Even now I’ll try to write a unit test for this and attach it below. |
I don't see any benefit for the package with this PR, I'm really sorry. I'm closing the pull request. |
@justinkekeocha It seems to me that a new section in the documentation needs to be created for this. If you have a desire, please add. |
I have done this here : https://github.com/bavix/laravel-wallet/pull/770 Is there a way to extend the Transaction and Transfer class? I am guessing it is editing this ` /**
|
Yes you are right. It's similar there. |
It will be nice to have a method that updates or adds a new key to the meta.
Just like what you did here: https://github.com/bavix/laravel-wallet/issues/498#issuecomment-1124005291