I'm trying to make a wallet system in my Laravel application.
Letme explain my database structure
first I have the default users table.
And each user hasOne wallet,
like this:
// User model
public function wallet()
{
return $this->hasOne(Wallet::class);
}
Now, what I want to achieve is whenever I query wallet
like:
$user->wallet
I want if the user doesn't have wallet a new wallet should be created automatically with default values.
I couldn't find a way to do this in a organized and efficient manner.
Please suggest a way.
Thank you so much for reading :)