用户配置转移

This commit is contained in:
2022-11-01 16:39:45 +08:00
parent 719a9ff89d
commit 87e650b2f1
14 changed files with 461 additions and 33 deletions

View File

@@ -2,17 +2,14 @@
namespace App\Models;
use App\Models\Traits\BelongsToUser;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Comment extends Model
{
use SoftDeletes;
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
use BelongsToUser;
public function parent(): BelongsTo
{

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\Traits\BelongsToUser;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -11,16 +12,12 @@ use Illuminate\Support\Str;
class Dynamic extends Model
{
use SoftDeletes;
use BelongsToUser;
protected $casts = [
'pictures' => 'json',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function getPicturesUrlAttribute(): array
{
$pictures = $this->getAttribute('pictures');

View File

@@ -2,7 +2,9 @@
namespace App\Models;
use App\Models\Traits\BelongsToUser;
class Group extends Model
{
use BelongsToUser;
}

View File

@@ -2,16 +2,14 @@
namespace App\Models;
use App\Models\Traits\BelongsToUser;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Like extends Model
{
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
use BelongsToUser;
public function likeable(): MorphTo
{

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Models\Traits;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
trait BelongsToUser
{
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@@ -30,6 +30,7 @@ class User extends Authenticatable
protected static function boot()
{
parent::boot();
self::created(function ($model) {
$model->info()->create([
'nickname' => '用户'.substr($model->username, -4),
@@ -40,6 +41,7 @@ class User extends Authenticatable
'FaceUrl' => '',
];
app('im')->send('im_open_login_svc', 'account_import', $params);
$model->setting()->create();
});
}
@@ -68,4 +70,9 @@ class User extends Authenticatable
{
return $this->hasOne(UserInfo::class);
}
public function setting(): HasOne
{
return $this->hasOne(UserSetting::class);
}
}

View File

@@ -2,23 +2,11 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Traits\BelongsToUser;
class UserInfo extends Model
{
use BelongsToUser;
protected $primaryKey = 'user_id';
protected static function boot()
{
parent::boot();
self::created(function ($model) {
});
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToUser;
class UserSetting extends Model
{
use BelongsToUser;
protected $primaryKey = 'user_id';
protected static function boot()
{
parent::boot();
self::creating(function ($model) {
$model->secret_key = app('pragmarx.google2fa')->generateSecretKey();
});
}
}