By "I want if the user doesn't have wallet a new wallet should be created automatically with default values" if you mean that you want some default values when using $user->wallet on frontend to avoid conditionals, you can use the handy withDefault() as below:
/**
* Get the wallet for the user.
*/
public function wallet()
{
return $this->hasOne(Wallet::class)->withDefault([
//Default values here
//This will not persist or create a record in database
// It will just return an instance of Wallet with default values defined here instead of null when a user doesn't have a Wallet yet
// It will help avoid conditionals say in frontend view
]);
}
You can read more at DefaultModel - Lavavel Docs
However if you want every user to have a default Wallet you can make use of Model hooks and create a Wallet for each user when a record is created.
class User extends Model
{
public static function booted()
{
static::created(function($user){
$user->wallet()->create([
//Default values here...
]);
});
}
// Rest of the User Model class code...
}
You can read more at Model Events - Laravel Docs