fix : 메뉴 모델 및 일부 서비스파일 response 오류 수정
This commit is contained in:
@@ -4,14 +4,25 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use App\Models\Scopes\TenantScope;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes, BelongsToTenant, ModelTrait;
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id', 'parent_id', 'slug', 'name', 'url', 'is_active', 'sort_order',
|
||||
'hidden', 'is_external', 'external_url', 'icon'
|
||||
'tenant_id', 'parent_id', 'name', 'url', 'is_active', 'sort_order',
|
||||
'hidden', 'is_external', 'external_url', 'icon',
|
||||
'created_by', 'updated_by', 'deleted_by',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
'deleted_at'
|
||||
];
|
||||
|
||||
public function parent()
|
||||
@@ -23,4 +34,23 @@ public function children()
|
||||
{
|
||||
return $this->hasMany(Menu::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 공유(NULL) + 현재 테넌트 모두 포함해서 조회
|
||||
* (SoftDeletes 글로벌 스코프는 그대로 유지)
|
||||
*/
|
||||
public function scopeWithShared($query, ?int $tenantId = null)
|
||||
{
|
||||
$tenantId = $tenantId ?? app('tenant_id');
|
||||
|
||||
return $query
|
||||
->withoutGlobalScope(TenantScope::class)
|
||||
->where(function ($w) use ($tenantId) {
|
||||
if (is_null($tenantId)) {
|
||||
$w->whereNull('tenant_id');
|
||||
} else {
|
||||
$w->whereNull('tenant_id')->orWhere('tenant_id', $tenantId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user