1) if not exists
public function wallet()
{
return $this->hasOne(Wallet::class)->withDefault([
'name' => 'Wallet Name',
]);
}
2) or force insert when user created please use observer|model boot
protected static function boot()
{
parent::boot();
static::created(static function (self $user) {
$wallet = new Wallet(['name' => 'Wallet Name']);
$user->wallet()->save($wallet);
});
}
Run code snippet
Code Example |
---|
Php :: How to order by using id with firstWhere in laravel |
Php :: laravel elequent get |
Php :: laravel query order by relation |
Php :: php call class method dynamically |
Php :: if exists in string php |
Php :: laravel value eloquent |
Php :: php api method post |
Php :: laravel pagination problem in blade |
Php :: laravel validation double |
Php :: laravel get id from insert |
Php :: wp image size names |
Php :: create model laravel |
Php :: laravel model with migration |
Php :: laravel use global variable in model |
Php :: if else if php code reflect |
Php :: wc php if is product category page |
Php :: php.hello |
Php :: @foreac laravel |
Php :: comment php |
Php :: distinct laravel not working |
Php :: php mod |
Php :: php new PDO timeout |
Php :: search laravel |
Php :: calculator in php |
Php :: gettype() function in PHP |
Php :: compact example in php |
Php :: how to set up the laravel ssh keygen |
Php :: get post id contact form 7 |
Php :: windows logged in user name in php |
Php :: php static variable |