用户配置转移
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToUser;
|
||||
|
||||
class Group extends Model
|
||||
{
|
||||
|
||||
use BelongsToUser;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
14
app/Models/Traits/BelongsToUser.php
Normal file
14
app/Models/Traits/BelongsToUser.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
21
app/Models/UserSetting.php
Normal file
21
app/Models/UserSetting.php
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user