fix : 테이블 추가 및 수정
- 신규 (user_roles, user_tenants) - 수정 (roles, tenants, users)
This commit is contained in:
@@ -14,4 +14,14 @@ public function menuPermissions()
|
||||
{
|
||||
return $this->hasMany(RoleMenuPermission::class, 'role_id');
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function userRoles()
|
||||
{
|
||||
return $this->hasMany(UserRole::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,24 @@ public function subscription()
|
||||
{
|
||||
return $this->belongsTo(Subscription::class, 'subscription_id');
|
||||
}
|
||||
|
||||
public function userTenants()
|
||||
{
|
||||
return $this->hasMany(UserTenant::class);
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_tenants');
|
||||
}
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->hasMany(Role::class);
|
||||
}
|
||||
|
||||
public function userRoles()
|
||||
{
|
||||
return $this->hasMany(UserRole::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,37 +6,29 @@
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use App\Traits\UppercaseAttributes;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, Notifiable, TwoFactorAuthenticatable;
|
||||
use HasApiTokens, Notifiable, TwoFactorAuthenticatable, SoftDeletes;
|
||||
|
||||
protected $table = 'members'; // 테이블 이름 변경
|
||||
|
||||
protected $primaryKey = 'mb_id'; // 기본 키 변경
|
||||
|
||||
protected $fillable = [
|
||||
'mb_id', 'mb_pass', 'mb_name', 'mb_phone', 'mb_mail',
|
||||
'email_verified_at', 'mb_type', 'mb_level', 'last_login',
|
||||
'reg_date', 'remember_token'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'mb_pass', 'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'reg_date' => 'datetime',
|
||||
];
|
||||
|
||||
public function getAuthPassword()
|
||||
public function userTenants()
|
||||
{
|
||||
return $this->mb_pass; // 기본 비밀번호 필드를 mb_pass로 설정
|
||||
return $this->hasMany(UserTenant::class);
|
||||
}
|
||||
|
||||
public function getAuthIdentifierName()
|
||||
public function tenants()
|
||||
{
|
||||
return 'mb_id'; // 기본 로그인 필드를 mb_id로 변경
|
||||
return $this->belongsToMany(Tenant::class, 'user_tenants');
|
||||
}
|
||||
|
||||
public function userRoles()
|
||||
{
|
||||
return $this->hasMany(UserRole::class);
|
||||
}
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'user_roles')
|
||||
->withPivot('tenant_id', 'assigned_at');
|
||||
}
|
||||
}
|
||||
|
||||
31
app/Models/UserRole.php
Normal file
31
app/Models/UserRole.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
|
||||
class UserRole extends Model
|
||||
{
|
||||
use SoftDeletes, BelongsToTenant;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'tenant_id', 'role_id', 'assigned_at'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
}
|
||||
25
app/Models/UserTenant.php
Normal file
25
app/Models/UserTenant.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class UserTenant extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'tenant_id', 'is_active', 'joined_at', 'left_at'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user