{"id":94,"date":"2024-03-04T14:39:48","date_gmt":"2024-03-04T14:39:48","guid":{"rendered":"http:\/\/localhost\/techteerblock\/?p=94"},"modified":"2024-03-19T09:11:08","modified_gmt":"2024-03-19T09:11:08","slug":"a-simple-wallet-implementation-for-laravel","status":"publish","type":"post","link":"https:\/\/techteer.net\/blog\/a-simple-wallet-implementation-for-laravel\/","title":{"rendered":"A SIMPLE WALLET IMPLEMENTATION FOR LARAVEL"},"content":{"rendered":"<p>Laravel\u00a0Wallet\u00a0by\u00a0Stephen Jude\u00a0is a simple wallet implementation for Laravel models:<br \/>\n1class User extends Authenticatable implements Wallet<br \/>\n2{<br \/>\n3 use HasWallet;<br \/>\n4}<br \/>\nUsing the\u00a0<strong>\u2018HasWallet\u2019<\/strong>\u00a0trait, you can add deposits, make withdrawals, and check the balance of the wallet for a given model:<br \/>\n1\/\/ Making deposits<br \/>\n2<br \/>\n3\/\/ returns the wallet balance: 200.22<br \/>\n4$user-&gt;deposit(200.22);<br \/>\n5<br \/>\n6\/\/ returns the wallet balance: 400.22<br \/>\n7$user-&gt;deposit(200);<br \/>\nGiven a wallet balance from the above example, you can make withdrawals:<br \/>\n1\/\/ returns the wallet balance: 200.22<br \/>\n2$user-&gt;withdraw(200);<br \/>\n3<br \/>\n4\/\/ returns the wallet balance: 200<br \/>\n5$user-&gt;withdraw(0.22);<br \/>\nIf you attempt to withdraw more than the amount in the wallet, the package will throw an exception:<br \/>\n1use Stephenjude\\Wallet\\Exceptions\\ InsufficientFundException;<br \/>\n2<br \/>\n3try {<br \/>\n4 $user-&gt;withdraw(5_000);<br \/>\n5} catch (InsufficientFundException $e) {<br \/>\n6 \/\/ Code to handle insufficient funds\u2026<br \/>\n7}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u00a0Wallet\u00a0by\u00a0Stephen Jude\u00a0is a simple wallet implementation for Laravel models: 1class&hellip;<\/p>\n","protected":false},"author":1,"featured_media":95,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-recent-posts"],"_links":{"self":[{"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":3,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions\/186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/media\/95"}],"wp:attachment":[{"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techteer.net\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}